Skip to content

Commit

Permalink
Update Discord API to v10
Browse files Browse the repository at this point in the history
  • Loading branch information
raykrueger committed Sep 22, 2024
1 parent d3aded0 commit 4c03897
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion resources/functions/discord/discord_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def handle(event, context):
print("Received event: " + json.dumps(event))
interaction_token = event["InteractionToken"]
message = event["Discord"]["Message"]
url = f"https://discord.com/api/v8/webhooks/{app_id}/{interaction_token}"
url = f"https://discord.com/api/v10/webhooks/{app_id}/{interaction_token}/callback"
headers = {"Authorization": f"Bot {bot_token}"}
res = requests.post(url, json={"content": message}, headers=headers)
res.raise_for_status()
6 changes: 4 additions & 2 deletions resources/functions/discord_provider/discord_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
secrets = secrets_manager.get_secret_value(SecretId=secret_name)["SecretString"]
secrets = json.loads(secrets)

discord_api_version = "v10"

app_id = secrets["AppId"]
guild_id = secrets["GuildId"]
bot_token = secrets["BotToken"]

command_name = os.environ.get("COMMAND_NAME")

def on_create(event):
url = f"https://discord.com/api/v10/applications/{app_id}/guilds/{guild_id}/commands"
url = f"https://discord.com/api/{discord_api_version}/applications/{app_id}/guilds/{guild_id}/commands"

# This is an example USER command, with a type of 2
blob = {
Expand Down Expand Up @@ -63,7 +65,7 @@ def on_update(event):

def on_delete(event):
command_id = event["PhysicalResourceId"]
url = f"https://discord.com/api/v8/applications/{app_id}/guilds/{guild_id}/commands/{command_id}"
url = f"https://discord.com/api/{discord_api_version}/applications/{app_id}/guilds/{guild_id}/commands/{command_id}"

# For authorization, you can use your bot token
headers = {"Authorization": f"Bearer {bot_token}"}
Expand Down

0 comments on commit 4c03897

Please sign in to comment.