Events¶
Events are dispatched whenever a subscribed event gets sent by Discord.
What Events Can I Get¶
What events you subscribe to are defined at startup by setting your Intents
.
Intents.DEFAULT
is a good place to start if your bot is new and small, otherwise, it is recommended to take your time and go through them one by one.
1 2 |
|
For more information, please visit the API reference here.
Hey Listen!!!¶
Now you can receive events. To respond to them, you need to register a callback. Callbacks should be lower-case, use _
instead of spaces and start with on_
.
Depending on how you register your callbacks that's not a requirement, but it is a good habit nonetheless.
For example, the event callback for the ChannelCreate
event should be called on_channel_create
.
You can find all events and their signatures here.
Be aware that your Intents
must be set to receive the event you are looking for.
There are two ways to register events. Decorators are the recommended way to do this.
To use decorators, they need to be in the same file where you defined your bot = Client()
.
1 2 3 4 5 6 7 8 9 |
|
You can also use @listen
with any function names:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
You can also register the events manually. This gives you the most flexibility, but it's not the cleanest.
1 2 3 4 5 6 7 8 9 |
|