mirror of
https://github.com/Paillat-dev/pycord-rest.git
synced 2026-01-02 09:06:20 +00:00
✨ Add webhook event handling for application authorization
This commit is contained in:
49
examples/webhook_events.py
Normal file
49
examples/webhook_events.py
Normal 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",
|
||||
},
|
||||
)
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user