Skip to content

Fix python discord command bot #330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions python/discord_command_bot/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,39 @@ def main(context):
)

if not verify_key(
context.req.body_bianary,
context.req.body_binary,
context.req.headers["x-signature-ed25519"],
context.req.headers["x-signature-timestamp"],
os.environ["DISCORD_PUBLIC_KEY"],
):
context.error("Invalid request")
return context.res.json({"error": "Invalid request signature"}, 401)

if context.req.body["type"] == 1:
context.log("Ping request - returning PONG")
return context.res.json(
{
"type": InteractionResponseType.PONG,
},
200,
)

context.log("Valid request")

interaction = context.req.body

if (interaction.type == InteractionType.APPLICATION_COMMAND) and (
interaction.data.name == "hello"
if (interaction["type"] == InteractionType.APPLICATION_COMMAND) and (
interaction["data"]["name"] == "hello"
):
context.log("Matched hello command - returning message")

return context.res.json(
{
"type": InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE,
"data": {
"tts": False,
"content": "Hello World!",
},
"embeds": [],
"allowed_mentions": {"parse": []}
}
},
200,
200
)

context.log("Didn't match command - returning PONG")

return context.res.json(
{
"type": InteractionResponseType.PONG,
},
200,
)
2 changes: 1 addition & 1 deletion python/discord_command_bot/src/setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import requests, os
from .utils import throw_if_missing
from utils import throw_if_missing


def setup():
Expand Down