Events¶
This section documents events related to the main library.
What are events?¶
So, what are events anyway? Most of the Client application cycle is based on events - special “notifications” usually sent by Discord
to notify client about certain actions like message deletion, :mmlol: emoji creation, member nickname update, etc.
This allows you to respond to certain actions by making another actions, about which Discord will notify other
connected clients (i.e., other bots and users). This library provides two main ways to register an
event handler - a special function which will watch to certain types of events and allow you to do anything you
want in response to those events.
The first way is through the use of the Client.event() decorator:
import disnake
client = disnake.Client()
@client.event
async def on_message(message):
if message.author.bot:
return
if message.content.startswith('$hello'):
await message.reply(f'Hello, {message.author}!')
The second way is through subclassing Client and
overriding the specific events. For example:
import disnake
class MyClient(disnake.Client):
async def on_message(self, message):
if message.author.bot:
return
if message.content.startswith('$hello'):
await message.reply(f'Hello, {message.author}!')
The above pieces of code are essentially equal, and both respond with “Hello, {message author’s username here}!” message when a user sends “$hello” message.
Warning
Event handlers described here are a bit different from Bot’s event listeners.
Client’s event handlers are unique: you can’t have two on_message(), two
on_member_ban() etc. With Bot however, you can have as much listeners
of the same type as you want.
Please also note that using Bot.event() decorator is the same as using Client’s
event() (since Bot subclasses Client) and does not allow to listen/watch
for multiple events of the same type. Consider using Bot.listen() for that.
Note
Events can be sent not only by Discord. For instance, if you use commands extension, you’ll also receive various events related to your commands’ execution process.
If an event handler raises an exception, on_error() will be called
to handle it, which defaults to print a traceback and ignoring the exception.
Warning
All the events must be a coroutine. If they aren’t, then you might get unexpected
errors. In order to turn a function into a coroutine they must be async def
functions.
Reference¶
Client¶
This section documents events related to Client and its connectivity to Discord.
- disnake.on_connect()¶
Called when the client has successfully connected to Discord. This is not the same as the client being fully prepared, see
on_ready()for that.The warnings on
on_ready()also apply.
- disnake.on_disconnect()¶
Called when the client has disconnected from Discord, or a connection attempt to Discord has failed. This could happen either through the internet being disconnected, explicit calls to close, or Discord terminating the connection one way or the other.
This function can be called many times without a corresponding
on_connect()call.
- disnake.on_error(event, *args, **kwargs)¶
Usually when an event raises an uncaught exception, a traceback is printed to stderr and the exception is ignored. If you want to change this behaviour and handle the exception for whatever reason yourself, this event can be overridden. Which, when done, will suppress the default action of printing the traceback.
The information of the exception raised and the exception itself can be retrieved with a standard call to
sys.exc_info().If you want exception to propagate out of the
Clientclass you can define anon_errorhandler consisting of a single empty raise statement. Exceptions raised byon_errorwill not be handled in any way byClient.Note
on_errorwill only be dispatched toClient.event().It will not be received by
Client.wait_for(), or, if used, Bots listeners such aslisten()orlistener().- Parameters:
event (
str) – The name of the event that raised the exception.args – The positional arguments for the event that raised the exception.
kwargs – The keyword arguments for the event that raised the exception.
- disnake.on_ready()¶
Called when the client is done preparing the data received from Discord. Usually after login is successful and the
Client.guildsand co. are filled up.Warning
This function is not guaranteed to be the first event called. Likewise, this function is not guaranteed to only be called once. This library implements reconnection logic and thus will end up calling this event whenever a RESUME request fails.
- disnake.on_resumed()¶
Called when the client has resumed a session.
- disnake.on_shard_connect(shard_id)¶
Similar to
on_connect()except used byAutoShardedClientto denote when a particular shard ID has connected to Discord.New in version 1.4.
- Parameters:
shard_id (
int) – The shard ID that has connected.
- disnake.on_shard_disconnect(shard_id)¶
Similar to
on_disconnect()except used byAutoShardedClientto denote when a particular shard ID has disconnected from Discord.New in version 1.4.
- Parameters:
shard_id (
int) – The shard ID that has disconnected.
- disnake.on_shard_ready(shard_id)¶
Similar to
on_ready()except used byAutoShardedClientto denote when a particular shard ID has become ready.- Parameters:
shard_id (
int) – The shard ID that is ready.
- disnake.on_shard_resumed(shard_id)¶
Similar to
on_resumed()except used byAutoShardedClientto denote when a particular shard ID has resumed a session.New in version 1.4.
- Parameters:
shard_id (
int) – The shard ID that has resumed.
- disnake.on_socket_event_type(event_type)¶
Called whenever a websocket event is received from the WebSocket.
This is mainly useful for logging how many events you are receiving from the Discord gateway.
New in version 2.0.
- Parameters:
event_type (
str) – The event type from Discord that is received, e.g.'READY'.
- disnake.on_socket_raw_receive(msg)¶
Called whenever a message is completely received from the WebSocket, before it’s processed and parsed. This event is always dispatched when a complete message is received and the passed data is not parsed in any way.
This is only really useful for grabbing the WebSocket stream and debugging purposes.
This requires setting the
enable_debug_eventssetting in theClient.Note
This is only for the messages received from the client WebSocket. The voice WebSocket will not trigger this event.
- Parameters:
msg (
str) – The message passed in from the WebSocket library.
- disnake.on_socket_raw_send(payload)¶
Called whenever a send operation is done on the WebSocket before the message is sent. The passed parameter is the message that is being sent to the WebSocket.
This is only really useful for grabbing the WebSocket stream and debugging purposes.
This requires setting the
enable_debug_eventssetting in theClient.Note
This is only for the messages sent from the client WebSocket. The voice WebSocket will not trigger this event.
- disnake.on_gateway_error(event, data, shard_id, exc)¶
When a (known) gateway event cannot be parsed, a traceback is printed to stderr and the exception is ignored by default. This should generally not happen and is usually either a library issue, or caused by a breaking API change.
To change this behaviour, for example to completely stop the bot, this event can be overridden.
This can also be disabled completely by passing
enable_gateway_error_handler=Falseto the client on initialization, restoring the pre-v2.6 behavior.New in version 2.6.
Note
on_gateway_errorwill only be dispatched toClient.event().It will not be received by
Client.wait_for(), or, if used, Bots listeners such aslisten()orlistener().Note
This will not be dispatched for exceptions that occur while parsing
READYandRESUMEDevent payloads, as exceptions in these events are considered fatal.
Channels/Threads¶
This section documents events related to Discord channels and threads.
- disnake.on_guild_channel_delete(channel)¶
- disnake.on_guild_channel_create(channel)¶
Called whenever a guild channel is deleted or created.
Note that you can get the guild from
guild.This requires
Intents.guildsto be enabled.- Parameters:
channel (
abc.GuildChannel) – The guild channel that got created or deleted.
- disnake.on_guild_channel_update(before, after)¶
Called whenever a guild channel is updated. e.g. changed name, topic, permissions.
This requires
Intents.guildsto be enabled.- Parameters:
before (
abc.GuildChannel) – The updated guild channel’s old info.after (
abc.GuildChannel) – The updated guild channel’s new info.
- disnake.on_guild_channel_pins_update(channel, last_pin)¶
Called whenever a message is pinned or unpinned from a guild channel.
This requires
Intents.guildsto be enabled.- Parameters:
channel (Union[
abc.GuildChannel,Thread]) – The guild channel that had its pins updated.last_pin (Optional[
datetime.datetime]) – The latest message that was pinned as an aware datetime in UTC. Could beNone.
- disnake.on_private_channel_update(before, after)¶
Called whenever a private group DM is updated. e.g. changed name or topic.
This requires
Intents.messagesto be enabled.- Parameters:
before (
GroupChannel) – The updated group channel’s old info.after (
GroupChannel) – The updated group channel’s new info.
- disnake.on_private_channel_pins_update(channel, last_pin)¶
Called whenever a message is pinned or unpinned from a private channel.
- Parameters:
channel (
abc.PrivateChannel) – The private channel that had its pins updated.last_pin (Optional[
datetime.datetime]) – The latest message that was pinned as an aware datetime in UTC. Could beNone.
- disnake.on_thread_create(thread)¶
Called whenever a thread is created.
Note that you can get the guild from
Thread.guild.This requires
Intents.guildsto be enabled.Note
This only works for threads created in channels the bot already has access to, and only for public threads unless the bot has the
manage_threadspermission.New in version 2.5.
- Parameters:
thread (
Thread) – The thread that got created.
- disnake.on_thread_join(thread)¶
Called whenever the bot joins a thread or gets access to a thread (for example, by gaining access to the parent channel).
Note that you can get the guild from
Thread.guild.This requires
Intents.guildsto be enabled.Note
This event will not be called for threads created by the bot or threads created on one of the bot’s messages.
New in version 2.0.
Changed in version 2.5: This is no longer being called when a thread is created, see
on_thread_create()instead.- Parameters:
thread (
Thread) – The thread that got joined.
- disnake.on_thread_member_join(member)¶
- disnake.on_thread_member_remove(member)¶
Called when a
ThreadMemberleaves or joins aThread.You can get the thread a member belongs in by accessing
ThreadMember.thread.On removal events, if the member being removed is not found in the internal cache, then this event will not be called. Consider using
on_raw_thread_member_remove()instead.This requires
Intents.membersto be enabled.New in version 2.0.
- Parameters:
member (
ThreadMember) – The member who joined or left.
- disnake.on_thread_remove(thread)¶
Called whenever a thread is removed. This is different from a thread being deleted.
Note that you can get the guild from
Thread.guild.This requires
Intents.guildsto be enabled.Warning
Due to technical limitations, this event might not be called as soon as one expects. Since the library tracks thread membership locally, the API only sends updated thread membership status upon being synced by joining a thread.
New in version 2.0.
- Parameters:
thread (
Thread) – The thread that got removed.
- disnake.on_thread_update(before, after)¶
Called when a thread is updated. If the thread is not found in the internal thread cache, then this event will not be called. Consider using
on_raw_thread_update()which will be called regardless of the cache.This requires
Intents.guildsto be enabled.New in version 2.0.
- disnake.on_thread_delete(thread)¶
Called when a thread is deleted. If the thread is not found in the internal thread cache, then this event will not be called. Consider using
on_raw_thread_delete()instead.Note that you can get the guild from
Thread.guild.This requires
Intents.guildsto be enabled.New in version 2.0.
- Parameters:
thread (
Thread) – The thread that got deleted.
- disnake.on_raw_thread_member_remove(payload)¶
Called when a
ThreadMemberleavesThread. Unlikeon_thread_member_remove(), this is called regardless of the thread member cache.You can get the thread a member belongs in by accessing
ThreadMember.thread.This requires
Intents.membersto be enabled.New in version 2.5.
- Parameters:
payload (
RawThreadMemberRemoveEvent) – The raw event payload data.
- disnake.on_raw_thread_update(after)¶
Called whenever a thread is updated. Unlike
on_thread_update(), this is called regardless of the state of the internal thread cache.This requires
Intents.guildsto be enabled.New in version 2.5.
- Parameters:
thread (
Thread) – The updated thread.
- disnake.on_raw_thread_delete(payload)¶
Called whenever a thread is deleted. Unlike
on_thread_delete(), this is called regardless of the state of the internal thread cache.Note that you can get the guild from
Thread.guild.This requires
Intents.guildsto be enabled.New in version 2.5.
- Parameters:
payload (
RawThreadDeleteEvent) – The raw event payload data.
- disnake.on_webhooks_update(channel)¶
Called whenever a webhook is created, modified, or removed from a guild channel.
This requires
Intents.webhooksto be enabled.- Parameters:
channel (
abc.GuildChannel) – The channel that had its webhooks updated.
Guilds¶
This section documents events related to Discord guilds.
General¶
- disnake.on_guild_join(guild)¶
Called when a
Guildis either created by theClientor when theClientjoins a guild.This requires
Intents.guildsto be enabled.- Parameters:
guild (
Guild) – The guild that was joined.
- disnake.on_guild_remove(guild)¶
Called when a
Guildis removed from theClient.This happens through, but not limited to, these circumstances:
The client got banned.
The client got kicked.
The client left the guild.
The client or the guild owner deleted the guild.
In order for this event to be invoked then the
Clientmust have been part of the guild to begin with. (i.e. it is part ofClient.guilds)This requires
Intents.guildsto be enabled.- Parameters:
guild (
Guild) – The guild that got removed.
- disnake.on_guild_update(before, after)¶
Called when a
Guildupdates, for example:Changed name
Changed AFK channel
Changed AFK timeout
etc
This requires
Intents.guildsto be enabled.
- disnake.on_guild_available(guild)¶
Called when a guild becomes available or unavailable. The guild must have existed in the
Client.guildscache.This requires
Intents.guildsto be enabled.- Parameters:
guild – The
Guildthat has changed availability.
Application Commands¶
- disnake.on_application_command_permissions_update(permissions)¶
Called when the permissions of an application command or the application-wide command permissions are updated.
Note that this will also be called when permissions of other applications change, not just this application’s permissions.
New in version 2.5.
- Parameters:
permissions (
GuildApplicationCommandPermissions) – The updated permission object.
AutoMod¶
- disnake.on_automod_action_execution(execution)¶
Called when an auto moderation action is executed due to a rule triggering for a particular event. You must have the
manage_guildpermission to receive this.The guild this action has taken place in can be accessed using
AutoModActionExecution.guild.This requires
Intents.automod_executionto be enabled.In addition,
Intents.message_contentmust be enabled to receive non-empty values forAutoModActionExecution.contentandAutoModActionExecution.matched_content.Note
This event will fire once per executed
AutoModAction, which means it will run multiple times when a rule is triggered, if that rule has multiple actions defined.New in version 2.6.
- Parameters:
execution (
AutoModActionExecution) – The auto moderation action execution data.
- disnake.on_automod_rule_create(rule)¶
Called when an
AutoModRuleis created. You must have themanage_guildpermission to receive this.This requires
Intents.automod_configurationto be enabled.New in version 2.6.
- Parameters:
rule (
AutoModRule) – The auto moderation rule that was created.
- disnake.on_automod_rule_update(rule)¶
Called when an
AutoModRuleis updated. You must have themanage_guildpermission to receive this.This requires
Intents.automod_configurationto be enabled.New in version 2.6.
- Parameters:
rule (
AutoModRule) – The auto moderation rule that was updated.
- disnake.on_automod_rule_delete(rule)¶
Called when an
AutoModRuleis deleted. You must have themanage_guildpermission to receive this.This requires
Intents.automod_configurationto be enabled.New in version 2.6.
- Parameters:
rule (
AutoModRule) – The auto moderation rule that was deleted.
Emojis¶
- disnake.on_guild_emojis_update(guild, before, after)¶
Called when a
Guildadds or removesEmoji.This requires
Intents.emojis_and_stickersto be enabled.
Integrations¶
- disnake.on_guild_integrations_update(guild)¶
Called whenever an integration is created, modified, or removed from a guild.
This requires
Intents.integrationsto be enabled.New in version 1.4.
- Parameters:
guild (
Guild) – The guild that had its integrations updated.
- disnake.on_integration_create(integration)¶
Called when an integration is created.
This requires
Intents.integrationsto be enabled.New in version 2.0.
- Parameters:
integration (
Integration) – The integration that was created.
- disnake.on_integration_update(integration)¶
Called when an integration is updated.
This requires
Intents.integrationsto be enabled.New in version 2.0.
- Parameters:
integration (
Integration) – The integration that was updated.
- disnake.on_raw_integration_delete(payload)¶
Called when an integration is deleted.
This requires
Intents.integrationsto be enabled.New in version 2.0.
- Parameters:
payload (
RawIntegrationDeleteEvent) – The raw event payload data.
Invites¶
- disnake.on_invite_create(invite)¶
Called when an
Inviteis created. You must have themanage_channelspermission to receive this.New in version 1.3.
Note
There is a rare possibility that the
Invite.guildandInvite.channelattributes will be ofObjectrather than the respective models.This requires
Intents.invitesto be enabled.- Parameters:
invite (
Invite) – The invite that was created.
- disnake.on_invite_delete(invite)¶
Called when an
Inviteis deleted. You must have themanage_channelspermission to receive this.New in version 1.3.
Note
There is a rare possibility that the
Invite.guildandInvite.channelattributes will be ofObjectrather than the respective models.Outside of those two attributes, the only other attribute guaranteed to be filled by the Discord gateway for this event is
Invite.code.This requires
Intents.invitesto be enabled.- Parameters:
invite (
Invite) – The invite that was deleted.
Members¶
- disnake.on_member_join(member)¶
- disnake.on_member_remove(member)¶
Called when a
Memberleaves or joins aGuild. Ifon_member_remove()is being used then consider usingon_raw_member_remove()which will be called regardless of the cache.This requires
Intents.membersto be enabled.- Parameters:
member (
Member) – The member who joined or left.
- disnake.on_member_update(before, after)¶
Called when a
Memberupdates their profile. Consider usingon_raw_member_update()which will be called regardless of the cache.This is called when one or more of the following things change, but is not limited to:
avatar (guild-specific)
current_timeout
nickname
pending
premium_since
roles
This requires
Intents.membersto be enabled.
- disnake.on_raw_member_remove(payload)¶
Called when a member leaves a
Guild. Unlikeon_member_remove(), this is called regardless of the member cache.New in version 2.6.
- Parameters:
payload (
RawGuildMemberRemoveEvent) – The raw event payload data.
- disnake.on_raw_member_update(member)¶
Called when a member updates their profile. Unlike
on_member_update(), this is called regardless of the member cache.New in version 2.6.
- Parameters:
member (
Member) – The member that was updated.
- disnake.on_member_ban(guild, user)¶
Called when user gets banned from a
Guild.This requires
Intents.bansto be enabled.
- disnake.on_member_unban(guild, user)¶
Called when a
Usergets unbanned from aGuild.This requires
Intents.bansto be enabled.
- disnake.on_presence_update(before, after)¶
Called when a
Memberupdates their presence.This is called when one or more of the following things change:
status
activity
This requires
Intents.presencesandIntents.membersto be enabled.New in version 2.0.
- disnake.on_user_update(before, after)¶
Called when a
Useris updated.This is called when one or more of the following things change, but is not limited to:
avatar
discriminator
name
public_flags
This requires
Intents.membersto be enabled.
Scheduled Events¶
- disnake.on_guild_scheduled_event_create(event)¶
- disnake.on_guild_scheduled_event_delete(event)¶
Called when a guild scheduled event is created or deleted.
This requires
Intents.guild_scheduled_eventsto be enabled.New in version 2.3.
- Parameters:
event (
GuildScheduledEvent) – The guild scheduled event that was created or deleted.
- disnake.on_guild_scheduled_event_update(before, after)¶
Called when a guild scheduled event is updated. The guild must have existed in the
Client.guildscache.This requires
Intents.guild_scheduled_eventsto be enabled.New in version 2.3.
- Parameters:
before (
GuildScheduledEvent) – The guild scheduled event before the update.after (
GuildScheduledEvent) – The guild scheduled event after the update.
- disnake.on_guild_scheduled_event_subscribe(event, user)¶
- disnake.on_guild_scheduled_event_unsubscribe(event, user)¶
Called when a user subscribes to or unsubscribes from a guild scheduled event.
This requires
Intents.guild_scheduled_eventsandIntents.membersto be enabled.New in version 2.3.
- Parameters:
event (
GuildScheduledEvent) – The guild scheduled event that the user subscribed to or unsubscribed from.user (Union[
Member,User]) – The user who subscribed to or unsubscribed from the event.
- disnake.on_raw_guild_scheduled_event_subscribe(payload)¶
- disnake.on_raw_guild_scheduled_event_unsubscribe(payload)¶
Called when a user subscribes to or unsubscribes from a guild scheduled event. Unlike
on_guild_scheduled_event_subscribe()andon_guild_scheduled_event_unsubscribe(), this is called regardless of the guild scheduled event cache.- Parameters:
payload (
RawGuildScheduledEventUserActionEvent) – The raw event payload data.
Stage Instances¶
- disnake.on_stage_instance_create(stage_instance)¶
- disnake.on_stage_instance_delete(stage_instance)¶
Called when a
StageInstanceis created or deleted for aStageChannel.New in version 2.0.
- Parameters:
stage_instance (
StageInstance) – The stage instance that was created or deleted.
- disnake.on_stage_instance_update(before, after)¶
Called when a
StageInstanceis updated.The following, but not limited to, examples illustrate when this event is called:
The topic is changed.
The privacy level is changed.
New in version 2.0.
- Parameters:
before (
StageInstance) – The stage instance before the update.after (
StageInstance) – The stage instance after the update.
Stickers¶
- disnake.on_guild_stickers_update(guild, before, after)¶
Called when a
Guildupdates its stickers.This requires
Intents.emojis_and_stickersto be enabled.New in version 2.0.
- Parameters:
guild (
Guild) – The guild who got their stickers updated.before (Sequence[
GuildSticker]) – A list of stickers before the update.after (Sequence[
GuildSticker]) – A list of stickers after the update.
Roles¶
- disnake.on_guild_role_create(role)¶
- disnake.on_guild_role_delete(role)¶
Called when a
Guildcreates or deletes a newRole.To get the guild it belongs to, use
Role.guild.This requires
Intents.guildsto be enabled.- Parameters:
role (
Role) – The role that was created or deleted.
- disnake.on_guild_role_update(before, after)¶
Called when a
Roleis changed guild-wide.This requires
Intents.guildsto be enabled.
Voice¶
- disnake.on_voice_state_update(member, before, after)¶
Called when a
Memberchanges theirVoiceState.The following, but not limited to, examples illustrate when this event is called:
A member joins a voice or stage channel.
A member leaves a voice or stage channel.
A member is muted or deafened by their own accord.
A member is muted or deafened by a guild administrator.
This requires
Intents.voice_statesto be enabled.- Parameters:
member (
Member) – The member whose voice states changed.before (
VoiceState) – The voice state prior to the changes.after (
VoiceState) – The voice state after the changes.
Interactions¶
This section documents events related to application commands and other interactions.
- disnake.on_application_command(interaction)¶
Called when an application command is invoked.
Warning
This is a low level function that is not generally meant to be used. Consider using
BotorInteractionBotinstead.Warning
If you decide to override this event and are using
Botor related types, make sure to callBot.process_application_commandsto ensure that the application commands are processed.New in version 2.0.
- Parameters:
interaction (
ApplicationCommandInteraction) – The interaction object.
- disnake.on_application_command_autocomplete(interaction)¶
Called when an application command autocomplete is called.
Warning
This is a low level function that is not generally meant to be used. Consider using
BotorInteractionBotinstead.Warning
If you decide to override this event and are using
Botor related types, make sure to callBot.process_app_command_autocompletionto ensure that the application command autocompletion is processed.New in version 2.0.
- Parameters:
interaction (
ApplicationCommandInteraction) – The interaction object.
- disnake.on_button_click(interaction)¶
Called when a button is clicked.
New in version 2.0.
- Parameters:
interaction (
MessageInteraction) – The interaction object.
- disnake.on_dropdown(interaction)¶
Called when a select menu is clicked.
New in version 2.0.
- Parameters:
interaction (
MessageInteraction) – The interaction object.
- disnake.on_interaction(interaction)¶
Called when an interaction happened.
This currently happens due to application command invocations or components being used.
Warning
This is a low level function that is not generally meant to be used.
New in version 2.0.
- Parameters:
interaction (
Interaction) – The interaction object.
- disnake.on_message_interaction(interaction)¶
Called when a message interaction happened.
This currently happens due to components being used.
New in version 2.0.
- Parameters:
interaction (
MessageInteraction) – The interaction object.
- disnake.on_modal_submit(interaction)¶
Called when a modal is submitted.
New in version 2.4.
- Parameters:
interaction (
ModalInteraction) – The interaction object.
Messages¶
This section documents events related to Discord chat messages.
- disnake.on_message(message)¶
Called when a
Messageis created and sent.This requires
Intents.messagesto be enabled.Warning
Your bot’s own messages and private messages are sent through this event. This can lead cases of ‘recursion’ depending on how your bot was programmed. If you want the bot to not reply to itself, consider checking the user IDs. Note that
Botdoes not have this problem.Note
Not all messages will have
content. This is a Discord limitation. See the docs ofIntents.message_contentfor more information.- Parameters:
message (
Message) – The current message.
- disnake.on_message_delete(message)¶
Called when a message is deleted. If the message is not found in the internal message cache, then this event will not be called. Messages might not be in cache if the message is too old or the client is participating in high traffic guilds.
If this occurs increase the
max_messagesparameter or use theon_raw_message_delete()event instead.This requires
Intents.messagesto be enabled.Note
Not all messages will have
content. This is a Discord limitation. See the docs ofIntents.message_contentfor more information.- Parameters:
message (
Message) – The deleted message.
- disnake.on_message_edit(before, after)¶
Called when a
Messagereceives an update event. If the message is not found in the internal message cache, then these events will not be called. Messages might not be in cache if the message is too old or the client is participating in high traffic guilds.If this occurs increase the
max_messagesparameter or use theon_raw_message_edit()event instead.Note
Not all messages will have
content. This is a Discord limitation. See the docs ofIntents.message_contentfor more information.The following non-exhaustive cases trigger this event:
A message has been pinned or unpinned.
The message content has been changed.
The message has received an embed.
For performance reasons, the embed server does not do this in a “consistent” manner.
The message’s embeds were suppressed or unsuppressed.
A call message has received an update to its participants or ending time.
This requires
Intents.messagesto be enabled.
- disnake.on_bulk_message_delete(messages)¶
Called when messages are bulk deleted. If none of the messages deleted are found in the internal message cache, then this event will not be called. If individual messages were not found in the internal message cache, this event will still be called, but the messages not found will not be included in the messages list. Messages might not be in cache if the message is too old or the client is participating in high traffic guilds.
If this occurs increase the
max_messagesparameter or use theon_raw_bulk_message_delete()event instead.This requires
Intents.messagesto be enabled.- Parameters:
messages (List[
Message]) – The messages that have been deleted.
- disnake.on_raw_message_delete(payload)¶
Called when a message is deleted. Unlike
on_message_delete(), this is called regardless of the message being in the internal message cache or not.If the message is found in the message cache, it can be accessed via
RawMessageDeleteEvent.cached_messageThis requires
Intents.messagesto be enabled.- Parameters:
payload (
RawMessageDeleteEvent) – The raw event payload data.
- disnake.on_raw_message_edit(payload)¶
Called when a message is edited. Unlike
on_message_edit(), this is called regardless of the state of the internal message cache.If the message is found in the message cache, it can be accessed via
RawMessageUpdateEvent.cached_message. The cached message represents the message before it has been edited. For example, if the content of a message is modified and triggers theon_raw_message_edit()coroutine, theRawMessageUpdateEvent.cached_messagewill return aMessageobject that represents the message before the content was modified.Due to the inherently raw nature of this event, the data parameter coincides with the raw data given by the gateway.
Since the data payload can be partial, care must be taken when accessing stuff in the dictionary. One example of a common case of partial data is when the
'content'key is inaccessible. This denotes an “embed” only edit, which is an edit in which only the embeds are updated by the Discord embed server.This requires
Intents.messagesto be enabled.- Parameters:
payload (
RawMessageUpdateEvent) – The raw event payload data.
- disnake.on_raw_bulk_message_delete(payload)¶
Called when a bulk delete is triggered. Unlike
on_bulk_message_delete(), this is called regardless of the messages being in the internal message cache or not.If the messages are found in the message cache, they can be accessed via
RawBulkMessageDeleteEvent.cached_messagesThis requires
Intents.messagesto be enabled.- Parameters:
payload (
RawBulkMessageDeleteEvent) – The raw event payload data.
- disnake.on_reaction_add(reaction, user)¶
Called when a message has a reaction added to it. Similar to
on_message_edit(), if the message is not found in the internal message cache, then this event will not be called. Consider usingon_raw_reaction_add()instead.Note
To get the
Messagebeing reacted, access it viaReaction.message.This requires
Intents.reactionsto be enabled.Note
This doesn’t require
Intents.memberswithin a guild context, but due to Discord not providing updated user information in a direct message it’s required for direct messages to receive this event. Consider usingon_raw_reaction_add()if you need this and do not otherwise want to enable the members intent.
- disnake.on_reaction_remove(reaction, user)¶
Called when a message has a reaction removed from it. Similar to on_message_edit, if the message is not found in the internal message cache, then this event will not be called.
Note
To get the message being reacted, access it via
Reaction.message.This requires both
Intents.reactionsandIntents.membersto be enabled.Note
Consider using
on_raw_reaction_remove()if you need this and do not want to enable the members intent.
- disnake.on_reaction_clear(message, reactions)¶
Called when a message has all its reactions removed from it. Similar to
on_message_edit(), if the message is not found in the internal message cache, then this event will not be called. Consider usingon_raw_reaction_clear()instead.This requires
Intents.reactionsto be enabled.
- disnake.on_reaction_clear_emoji(reaction)¶
Called when a message has a specific reaction removed from it. Similar to
on_message_edit(), if the message is not found in the internal message cache, then this event will not be called. Consider usingon_raw_reaction_clear_emoji()instead.This requires
Intents.reactionsto be enabled.New in version 1.3.
- Parameters:
reaction (
Reaction) – The reaction that got cleared.
- disnake.on_raw_reaction_add(payload)¶
Called when a message has a reaction added. Unlike
on_reaction_add(), this is called regardless of the state of the internal message cache.This requires
Intents.reactionsto be enabled.- Parameters:
payload (
RawReactionActionEvent) – The raw event payload data.
- disnake.on_raw_reaction_remove(payload)¶
Called when a message has a reaction removed. Unlike
on_reaction_remove(), this is called regardless of the state of the internal message cache.This requires
Intents.reactionsto be enabled.- Parameters:
payload (
RawReactionActionEvent) – The raw event payload data.
- disnake.on_raw_reaction_clear(payload)¶
Called when a message has all its reactions removed. Unlike
on_reaction_clear(), this is called regardless of the state of the internal message cache.This requires
Intents.reactionsto be enabled.- Parameters:
payload (
RawReactionClearEvent) – The raw event payload data.
- disnake.on_raw_reaction_clear_emoji(payload)¶
Called when a message has a specific reaction removed from it. Unlike
on_reaction_clear_emoji()this is called regardless of the state of the internal message cache.This requires
Intents.reactionsto be enabled.New in version 1.3.
- Parameters:
payload (
RawReactionClearEmojiEvent) – The raw event payload data.
- disnake.on_typing(channel, user, when)¶
Called when someone begins typing a message.
The
channelparameter can be aabc.Messageableinstance, or aForumChannel. If channel is anabc.Messageableinstance, it could be aTextChannel,VoiceChannel,GroupChannel, orDMChannel.Changed in version 2.5:
channelmay be a typeForumChannelIf the
channelis aTextChannel,ForumChannel, orVoiceChannelthen theuserparameter is aMember, otherwise it is aUser.If the
channelis aDMChanneland the user is not found in the internal user/member cache, then this event will not be called. Consider usingon_raw_typing()instead.This requires
Intents.typingandIntents.guildsto be enabled.Note
This doesn’t require
Intents.memberswithin a guild context, but due to Discord not providing updated user information in a direct message it’s required for direct messages to receive this event, if the bot didn’t explicitly open the DM channel in the same session (throughUser.create_dm(),Client.create_dm(), or indirectly by sending a message to the user). Consider usingon_raw_typing()if you need this and do not otherwise want to enable the members intent.- Parameters:
channel (Union[
abc.Messageable,ForumChannel]) – The location where the typing originated from.when (
datetime.datetime) – When the typing started as an aware datetime in UTC.
- disnake.on_raw_typing(data)¶
Called when someone begins typing a message.
This is similar to
on_typing()except that it is called regardless of whetherIntents.membersandIntents.guildsare enabled.- Parameters:
data (
RawTypingEvent) – The raw event payload data.