What are Events?
Events are asynchronous callbacks that Pycord dispatches when specific actions occur on Discord. Your bot can listen to these events and respond accordingly. The event system is implemented indiscord/client.py:487 using the dispatch method, which triggers all registered event handlers.
Listening to Events
- Using @bot.event
- Using @bot.listen
- Using add_listener
- One-Time Events
The most common way to listen to events is using the
@bot.event decorator:Using
@bot.event replaces the default handler. Use @bot.listen to add additional handlers.Common Events
Connection Events
on_ready
on_ready
Called when the bot has successfully connected to Discord and the internal cache is ready.
on_connect
on_connect
Called when the bot establishes a connection to Discord (before cache is ready).
on_disconnect
on_disconnect
Called when the bot loses connection to Discord.
Message Events
on_message
on_message
Called when a message is sent in a channel the bot can see.Requires Intent:
guild_messages and/or dm_messagesRequires Privileged Intent: message_content (to read message content in guilds)on_message_edit
on_message_edit
Called when a message is edited.
on_message_delete
on_message_delete
Called when a message is deleted.
Member Events
on_member_join
on_member_join
Called when a member joins a guild.Requires Privileged Intent:
memberson_member_remove
on_member_remove
Called when a member leaves or is kicked from a guild.Requires Privileged Intent:
memberson_member_update
on_member_update
Called when a member’s properties change (roles, nickname, etc.).Requires Privileged Intent:
membersReaction Events
on_reaction_add
on_reaction_add
Called when a reaction is added to a message.
on_reaction_remove
on_reaction_remove
Called when a reaction is removed from a message.
Guild Events
on_guild_join
on_guild_join
Called when the bot joins a guild.
on_guild_remove
on_guild_remove
Called when the bot leaves or is removed from a guild.
Waiting for Events
Sometimes you need to wait for a specific event before continuing. Usebot.wait_for() for this:
Wait for Reaction
Event Error Handling
Handle errors that occur in event handlers:Complete Event Reference
Here’s a comprehensive list of all available events:Connection
on_connect- Bot connects to WebSocketon_disconnect- Bot disconnects from WebSocketon_ready- Bot is fully readyon_resumed- Bot resumes session after disconnect
Messages
on_message- Message is senton_message_edit- Message is editedon_message_delete- Message is deletedon_bulk_message_delete- Multiple messages deletedon_raw_message_edit- Message edited (raw data)on_raw_message_delete- Message deleted (raw data)
Reactions
on_reaction_add- Reaction addedon_reaction_remove- Reaction removedon_reaction_clear- All reactions clearedon_reaction_clear_emoji- All reactions of emoji clearedon_raw_reaction_add- Reaction added (raw data)on_raw_reaction_remove- Reaction removed (raw data)
Members
on_member_join- Member joins guildon_member_remove- Member leaves guildon_member_update- Member profile updatedon_user_update- User account updatedon_member_ban- Member bannedon_member_unban- Member unbanned
Guilds
on_guild_join- Bot joins guildon_guild_remove- Bot leaves guildon_guild_update- Guild settings updatedon_guild_available- Guild becomes availableon_guild_unavailable- Guild becomes unavailable
Channels
on_guild_channel_create- Channel createdon_guild_channel_delete- Channel deletedon_guild_channel_update- Channel updatedon_guild_channel_pins_update- Channel pins updated
Roles
on_guild_role_create- Role createdon_guild_role_delete- Role deletedon_guild_role_update- Role updated
Voice
on_voice_state_update- Voice state changes
Interactions
on_interaction- Any interaction receivedon_application_command- Slash command invokedon_application_command_error- Slash command error
And Many More!
on_typing- User starts typingon_invite_create/on_invite_delete- Invite managementon_webhooks_update- Webhook updatedon_presence_update- User presence changeson_scheduled_event_create/update/delete- Event management
Complete Example
Here’s a complete bot with multiple event handlers:Best Practices
- Always check if the author is a bot to avoid infinite loops
- Use
bot.listen()for multiple handlers instead of replacing withbot.event - Call
await bot.process_commands(message)inon_messageif using command extensions - Add error handling with
on_errorto catch issues - Use
wait_for()for interactive commands instead of polling - Check required intents - some events need specific intents enabled
