Add webhook event handling for application authorization

This commit is contained in:
2025-03-09 16:25:17 +01:00
parent 2a77346690
commit a133ca87cf
2 changed files with 50 additions and 1 deletions

View File

@@ -0,0 +1,49 @@
# Copyright (c) Paillat-dev
# SPDX-License-Identifier: MIT
"""Basic Discord bot example using Pycord REST.
This is a minimal example showing how to create slash commands.
"""
import logging
import os
from dotenv import load_dotenv
from pycord_rest import App, ApplicationAuthorizedEvent
# Load environment variables from .env file
load_dotenv()
# Set up logging
logging.basicConfig(level=logging.DEBUG)
app = App()
# Register the event handler
@app.listen("on_application_authorized")
async def on_application_authorized(event: ApplicationAuthorizedEvent) -> None:
if not event.guild:
print(f"User {event.user.display_name} ({event.user.id}) installed the application.")
else:
print(
f"Bot {event.user.display_name} ({event.user.id}) installed the application" # noqa: ISC003
+ f" to guild {event.guild.name} ({event.guild.id})."
)
# Run the app
if __name__ == "__main__":
app.run(
token=os.environ["DISCORD_TOKEN"],
public_key=os.environ["DISCORD_PUBLIC_KEY"],
uvicorn_options={
"host": "0.0.0.0", # noqa: S104
"port": 8000,
"log_level": "info",
},
)

View File

@@ -90,7 +90,7 @@ exclude = [
[tool.ruff.lint]
select = ["ALL"]
per-file-ignores = { "examples/**/*" = ["INP001", "ARG002"] }
per-file-ignores = { "examples/**/*" = ["INP001", "ARG002", "T201"] }
extend-ignore = [
"N999",
"D104",