djs_rs/event/mod.rs
1//! Typed client events (D-222).
2//!
3//! Every event is a zero-sized value on [`Events`] — `Events::MessageCreate`,
4//! `Events::GuildMemberUpdate`, … — whose type determines the payload a handler receives:
5//!
6//! ```no_run
7//! # use djs_rs::prelude::*;
8//! # let client = Client::builder("token").build();
9//! client.on(Events::MessageCreate, |_ctx, message| async move {
10//! // `message` is an `Arc<MessageCreate>`, which dereferences to `Message`.
11//! println!("{}", message.content);
12//! Ok(())
13//! });
14//!
15//! client.on(Events::MessageUpdate, |_ctx, update| async move {
16//! // `update.old` is the cached message before the edit, if the cache held it (D-221);
17//! // the payload dereferences to the new message.
18//! let before = update.old.as_ref().map(|old| old.content.as_str());
19//! println!("{before:?} -> {}", update.content);
20//! Ok(())
21//! });
22//! ```
23//!
24//! # What a handler receives
25//!
26//! - Most events hand their [`djs-model`](djs_model) payload unchanged, behind an `Arc`
27//! (D-225).
28//! - Events whose discord.js counterpart hands an old or removed object (D-227) hand a type
29//! from [`payload`] with the state the cache held before the event in `old` and Discord's
30//! data in `new`, and dereference to `new` (D-228). `old` is `None` without a cache, with
31//! the resource disabled in [`CacheConfig`](djs_cache::CacheConfig), or for something the
32//! cache never received.
33//! - Some events are derived by the client (D-223): [`GuildAvailable`] /
34//! [`GuildUnavailable`] / [`GuildCreate`] / [`GuildDelete`] are told apart with or without
35//! a cache; the per-emoji and per-sticker events need that resource in the cache.
36//! - [`Raw`] hands every gateway dispatch as its [`DispatchEvent`] before anything else.
37//!
38//! # Order
39//!
40//! For each gateway dispatch the client first applies it to the cache (D-171), then emits
41//! [`Raw`], then the event itself, then the events derived from it (for example
42//! [`GuildEmojisUpdate`], then one [`GuildEmojiCreate`] per new emoji).
43//!
44//! # Intents
45//!
46//! Each event lists the [`Intents`] Discord sends it with, also
47//! as [`Event::INTENTS`]; events without an intent are always sent. At login the client warns
48//! about handlers whose events none of its intents covers (D-271), and
49//! [`Client::required_intents`](crate::Client::required_intents) tells which intents the
50//! registered handlers need (D-272). Message content in guilds also needs the privileged
51//! `MESSAGE_CONTENT` intent, which no event lists: without it the content, embeds,
52//! attachments and components of other users' messages arrive empty.
53//!
54//! # Partials (discord.js)
55//!
56//! discord.js drops events about objects it has not cached unless the matching `partials`
57//! are enabled. djs-rs has no such option (D-273): every event arrives, and what the cache
58//! did not hold is simply missing — `old` is `None`, and payloads carry IDs where Discord
59//! sends IDs. Complete them with the managers when needed:
60//!
61//! | discord.js partial | What djs-rs hands instead | To complete it |
62//! |---|---|---|
63//! | `Partials.Message` | [`MessageUpdate`] / [`MessageDelete`] with `old: None` (`MessageUpdate` still has the new message) | `ctx.messages(channel).fetch(id)` (not after a deletion) |
64//! | `Partials.Channel` | DM events arrive without a cached channel; the payloads carry `channel_id` | `ctx.channels().fetch(id)` |
65//! | `Partials.Reaction` | [`MessageReactionAdd`] / [`MessageReactionRemove`] carry the message, channel and user IDs | `ctx.messages(channel).fetch(message)` |
66//! | `Partials.User` | user IDs (`user_id`) in reaction, typing and poll events | `ctx.users().fetch(id)` |
67//! | `Partials.GuildMember` | [`GuildMemberUpdate`] / [`GuildMemberRemove`] with `old: None` (the new data or the user) | `ctx.members(guild).fetch(user)` |
68//! | `Partials.ThreadMember` | [`ThreadMemberUpdate`] / [`ThreadMembersUpdate`] payloads as Discord sends them | `ctx.thread_members(thread).fetch(user)` |
69//! | `Partials.GuildScheduledEvent` | [`GuildScheduledEventUserAdd`] / [`GuildScheduledEventUserRemove`] with IDs; update / delete with `old: None` | `ctx.scheduled_events(guild).fetch(id)` |
70//! | `Partials.SoundboardSound` | soundboard update / delete with `old: None` | `ctx.soundboard_sounds(guild).fetch(id)` |
71//! | `Partials.Poll`, `Partials.PollAnswer` | [`MessagePollVoteAdd`] / [`MessagePollVoteRemove`] with the message ID and answer ID | `ctx.messages(channel).fetch(message)` (its `poll`) |
72//!
73//! discord.js counterpart: the `Events` enum.
74
75use std::sync::Arc;
76
77#[cfg(feature = "gateway")]
78use djs_gateway::ReceiveError;
79/// Without the gateway no shard runs, so [`ShardError`] is never emitted (C-141).
80#[cfg(not(feature = "gateway"))]
81type ReceiveError = core::convert::Infallible;
82use djs_model::gateway::{CloseCode, DispatchEvent, Intents, ShardId, payload as gateway};
83
84pub mod payload;
85
86/// Defines [`Events`], one marker type and [`Event`] impl per event, [`EventKind`] and
87/// [`Dispatch`] from one list, so they cannot drift apart.
88macro_rules! events {
89 ($(
90 $(#[$doc:meta])*
91 $name:ident = $js:literal => $payload:ty [$($intent:ident)|*];
92 )*) => {
93 /// The events a [`Client`](crate::Client) can emit, as typed values (D-222).
94 ///
95 /// Pass one of these to [`Client::on`](crate::Client::on). The names are those of
96 /// discord.js' `Events` (`Events.MessageCreate`, `Events.GuildRoleUpdate`, …); gateway
97 /// dispatches discord.js has no event for are named after the dispatch
98 /// (`INTEGRATION_CREATE` is [`IntegrationCreate`](Self::IntegrationCreate)).
99 ///
100 /// See the [module documentation](self) for what handlers receive and in which order.
101 #[derive(Clone, Copy, Debug)]
102 #[non_exhaustive]
103 pub struct Events;
104
105 #[expect(
106 non_upper_case_globals,
107 reason = "event names mirror discord.js' `Events.MessageCreate` style"
108 )]
109 impl Events {
110 $(
111 $(#[$doc])*
112 pub const $name: $name = $name;
113 )*
114 }
115
116 $(
117 $(#[$doc])*
118 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
119 #[non_exhaustive]
120 pub struct $name;
121
122 impl sealed::Sealed for $name {}
123
124 impl Event for $name {
125 type Payload = $payload;
126 const NAME: &'static str = $js;
127 const KIND: EventKind = EventKind::$name;
128 const INTENTS: Intents = Intents::empty()$(.union(Intents::$intent))*;
129
130 fn payload(dispatch: &Dispatch) -> Option<&Arc<$payload>> {
131 match dispatch {
132 Dispatch::$name(payload) => Some(payload),
133 _ => None,
134 }
135 }
136 }
137 )*
138
139 /// Identifies an event; used to index the handler table.
140 #[doc(hidden)]
141 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
142 pub enum EventKind {
143 $($name,)*
144 }
145
146 impl EventKind {
147 /// The number of events.
148 pub(crate) const COUNT: usize = [$(EventKind::$name),*].len();
149
150 /// Every event, in [`EventKind`] order.
151 pub(crate) const ALL: [Self; Self::COUNT] = [$(EventKind::$name),*];
152
153 /// The intents Discord sends the event under ([`Event::INTENTS`]).
154 pub(crate) const fn intents(self) -> Intents {
155 match self {
156 $(Self::$name => <$name as Event>::INTENTS,)*
157 }
158 }
159
160 /// The event's name as discord.js spells it ([`Event::NAME`]).
161 pub(crate) const fn name(self) -> &'static str {
162 match self {
163 $(Self::$name => $js,)*
164 }
165 }
166 }
167
168 /// An event as delivered by [`Client::events`](crate::Client::events): one variant per
169 /// event of [`Events`], with the payload its handlers receive.
170 ///
171 /// [`Raw`] is only delivered to handlers, never to event streams (they already receive
172 /// every event).
173 ///
174 /// discord.js counterpart: none (one variant per member of `Events`).
175 #[derive(Clone, Debug)]
176 #[non_exhaustive]
177 pub enum Dispatch {
178 $(
179 #[doc = concat!("The [`", stringify!($name), "`] event.")]
180 $name(Arc<$payload>),
181 )*
182 /// A gateway dispatch this version of the library does not know, with its name.
183 Unknown(Arc<str>),
184 }
185
186 impl Dispatch {
187 /// Returns the event's name as discord.js spells it (`"messageCreate"`), or the
188 /// Discord name of an [`Unknown`](Self::Unknown) dispatch.
189 #[must_use]
190 pub fn name(&self) -> &str {
191 match self {
192 $(Self::$name(_) => $js,)*
193 Self::Unknown(name) => name,
194 }
195 }
196
197 /// Returns which event this is (`None` for unknown dispatches).
198 pub(crate) const fn kind(&self) -> Option<EventKind> {
199 match self {
200 $(Self::$name(_) => Some(EventKind::$name),)*
201 Self::Unknown(_) => None,
202 }
203 }
204 }
205 };
206}
207
208/// A typed event that can be passed to [`Client::on`](crate::Client::on).
209///
210/// Implemented by the zero-sized event types on [`Events`]; sealed, so the set of events is
211/// controlled by this crate.
212///
213/// discord.js counterpart: a member of `Events` (each one a type here).
214pub trait Event: Copy + Send + Sync + 'static + sealed::Sealed {
215 /// The data a handler of this event receives (behind an `Arc`).
216 type Payload: Send + Sync + 'static;
217
218 /// The event's name as discord.js spells it, such as `"messageCreate"`.
219 const NAME: &'static str;
220
221 #[doc(hidden)]
222 const KIND: EventKind;
223
224 /// The [gateway intents](https://docs.discord.com/developers/events/gateway#list-of-intents)
225 /// Discord sends this event under: the client receives it if it requests any of them (for
226 /// [`MessageCreate`] guild messages come with `GUILD_MESSAGES`, direct messages with
227 /// `DIRECT_MESSAGES`). Empty for events sent without an intent, such as
228 /// [`InteractionCreate`] or the client's own lifecycle events. The client warns at login
229 /// about handlers whose events none of its intents cover (D-271).
230 const INTENTS: Intents;
231
232 #[doc(hidden)]
233 fn payload(dispatch: &Dispatch) -> Option<&Arc<Self::Payload>>;
234}
235
236mod sealed {
237 pub trait Sealed {}
238}
239
240events! {
241 // --- The client and its shards -------------------------------------------------------
242
243 /// The client is ready: fired once per [`login`](crate::Client::login), at the `READY` of
244 /// the last of its shards to become ready (D-224).
245 ///
246 /// It does **not** wait for the guilds' `GUILD_CREATE`s, so the cache may still be filling
247 /// (discord.js waits for them). The payload is that shard's `READY`: its `user` and
248 /// `application` are the same on every shard, its `guilds` are that shard's.
249 ///
250 /// discord.js: `Events.ClientReady` (`clientReady`).
251 ClientReady = "clientReady" => gateway::Ready [];
252
253 /// A shard's session is ready (`READY`): after connecting, and again after every
254 /// re-identify (not after a resume, see [`ShardResume`]).
255 ///
256 /// The shard is [`Context::shard_id`](crate::Context::shard_id); the guilds in the payload
257 /// arrive as [`GuildAvailable`] afterwards.
258 ///
259 /// discord.js: `Events.ShardReady` (`shardReady`).
260 ShardReady = "shardReady" => gateway::Ready [];
261
262 /// A shard resumed its session (`RESUMED`) after a reconnect; Discord replayed the events
263 /// it missed, counted in [`ShardResume::replayed`](payload::ShardResume::replayed).
264 ///
265 /// discord.js: `Events.ShardResume` (`shardResume`).
266 ShardResume = "shardResume" => payload::ShardResume [];
267
268 /// A shard lost its connection and is reconnecting (it resumes when it can, otherwise
269 /// it identifies again).
270 ///
271 /// Fired at the first event after the connection was lost, at the latest at the new
272 /// connection's hello.
273 ///
274 /// discord.js: `Events.ShardReconnecting` (`shardReconnecting`).
275 ShardReconnecting = "shardReconnecting" => payload::ShardReconnecting [];
276
277 /// Discord invalidated a shard's session (`INVALID_SESSION` that cannot be resumed): the
278 /// shard identifies again, and the events in between are lost.
279 ///
280 /// discord.js lists `Events.Invalidated` (`invalidated`) but v14 no longer emits it; here
281 /// it marks a lost session.
282 Invalidated = "invalidated" => payload::Invalidated [];
283
284 /// A shard hit an error it recovers from (a failed connection, a payload that could not
285 /// be decoded, …); it reconnects or skips the payload by itself.
286 ///
287 /// discord.js: `Events.ShardError` (`shardError`).
288 ShardError = "shardError" => ReceiveError [];
289
290 /// A shard was closed by Discord with a code that forbids reconnecting (an invalid token,
291 /// disallowed intents, …); the [`Client`](crate::Client) stops and
292 /// [`login`](crate::Client::login) returns the error.
293 ///
294 /// discord.js: `Events.ShardDisconnect` (`shardDisconnect`).
295 ShardDisconnect = "shardDisconnect" => CloseCode [];
296
297 /// Every gateway dispatch, decoded, before the cache's events and the derived ones.
298 ///
299 /// Only handlers receive it; registering one costs a clone of every dispatch.
300 ///
301 /// discord.js: `Events.Raw` (`raw`), which hands the undecoded packet.
302 Raw = "raw" => DispatchEvent [];
303
304 // --- Applications, auto moderation, monetization ------------------------------------
305
306 /// An application command's permissions were updated (`APPLICATION_COMMAND_PERMISSIONS_UPDATE`).
307 ///
308 /// discord.js: `Events.ApplicationCommandPermissionsUpdate`.
309 ApplicationCommandPermissionsUpdate = "applicationCommandPermissionsUpdate"
310 => gateway::ApplicationCommandPermissionsUpdate [];
311
312 /// An auto moderation rule acted on a message or member
313 /// (`AUTO_MODERATION_ACTION_EXECUTION`). Intent: `AUTO_MODERATION_EXECUTION`.
314 ///
315 /// discord.js: `Events.AutoModerationActionExecution`.
316 AutoModerationActionExecution = "autoModerationActionExecution"
317 => gateway::AutoModerationActionExecution [AUTO_MODERATION_EXECUTION];
318
319 /// An auto moderation rule was created (`AUTO_MODERATION_RULE_CREATE`). Intent:
320 /// `AUTO_MODERATION_CONFIGURATION`.
321 ///
322 /// discord.js: `Events.AutoModerationRuleCreate`.
323 AutoModerationRuleCreate = "autoModerationRuleCreate" => gateway::AutoModerationRuleCreate [AUTO_MODERATION_CONFIGURATION];
324
325 /// An auto moderation rule was updated (`AUTO_MODERATION_RULE_UPDATE`). Intent:
326 /// `AUTO_MODERATION_CONFIGURATION`.
327 ///
328 /// The cache does not keep rules, so there is no old rule (C-091).
329 ///
330 /// discord.js: `Events.AutoModerationRuleUpdate`.
331 AutoModerationRuleUpdate = "autoModerationRuleUpdate" => gateway::AutoModerationRuleUpdate [AUTO_MODERATION_CONFIGURATION];
332
333 /// An auto moderation rule was deleted (`AUTO_MODERATION_RULE_DELETE`). Intent:
334 /// `AUTO_MODERATION_CONFIGURATION`.
335 ///
336 /// discord.js: `Events.AutoModerationRuleDelete`.
337 AutoModerationRuleDelete = "autoModerationRuleDelete" => gateway::AutoModerationRuleDelete [AUTO_MODERATION_CONFIGURATION];
338
339 /// A user subscribed to a SKU (`ENTITLEMENT_CREATE`).
340 ///
341 /// discord.js: `Events.EntitlementCreate`.
342 EntitlementCreate = "entitlementCreate" => gateway::EntitlementCreate [];
343
344 /// An entitlement was updated, for example renewed (`ENTITLEMENT_UPDATE`).
345 ///
346 /// discord.js: `Events.EntitlementUpdate`.
347 EntitlementUpdate = "entitlementUpdate" => gateway::EntitlementUpdate [];
348
349 /// An entitlement was deleted (`ENTITLEMENT_DELETE`).
350 ///
351 /// discord.js: `Events.EntitlementDelete`.
352 EntitlementDelete = "entitlementDelete" => gateway::EntitlementDelete [];
353
354 /// A premium subscription was created (`SUBSCRIPTION_CREATE`).
355 ///
356 /// discord.js: `Events.SubscriptionCreate`.
357 SubscriptionCreate = "subscriptionCreate" => gateway::SubscriptionCreate [];
358
359 /// A premium subscription was updated (`SUBSCRIPTION_UPDATE`).
360 ///
361 /// discord.js: `Events.SubscriptionUpdate`.
362 SubscriptionUpdate = "subscriptionUpdate" => gateway::SubscriptionUpdate [];
363
364 /// A premium subscription was deleted (`SUBSCRIPTION_DELETE`).
365 ///
366 /// discord.js: `Events.SubscriptionDelete`.
367 SubscriptionDelete = "subscriptionDelete" => gateway::SubscriptionDelete [];
368
369 // --- Channels and threads -----------------------------------------------------------
370
371 /// A guild channel was created (`CHANNEL_CREATE`). Intent: `GUILDS`.
372 ///
373 /// discord.js: `Events.ChannelCreate`.
374 ChannelCreate = "channelCreate" => gateway::ChannelCreate [GUILDS];
375
376 /// A channel was updated (`CHANNEL_UPDATE`), with the cached channel before the update.
377 /// Intent: `GUILDS`.
378 ///
379 /// discord.js: `Events.ChannelUpdate` (`oldChannel`, `newChannel`).
380 ChannelUpdate = "channelUpdate" => payload::ChannelUpdate [GUILDS];
381
382 /// A channel was deleted (`CHANNEL_DELETE`), with the cached channel. Intent: `GUILDS`.
383 ///
384 /// discord.js: `Events.ChannelDelete`.
385 ChannelDelete = "channelDelete" => payload::ChannelDelete [GUILDS];
386
387 /// A message was pinned or unpinned (`CHANNEL_PINS_UPDATE`). Intents: `GUILDS`,
388 /// `DIRECT_MESSAGES`.
389 ///
390 /// discord.js: `Events.ChannelPinsUpdate`.
391 ChannelPinsUpdate = "channelPinsUpdate" => gateway::ChannelPinsUpdate [GUILDS | DIRECT_MESSAGES];
392
393 /// The ephemeral data of a guild's channels (`CHANNEL_INFO`), the answer to a
394 /// [`RequestChannelInfo`](djs_model::gateway::payload::RequestChannelInfo) command.
395 ///
396 /// discord.js has no such event (C-091).
397 ChannelInfo = "channelInfo" => gateway::ChannelInfo [];
398
399 /// A thread was created, or the bot was added to one (`THREAD_CREATE`). Intent: `GUILDS`.
400 ///
401 /// discord.js: `Events.ThreadCreate` (`newly_created` is a field of the payload).
402 ThreadCreate = "threadCreate" => gateway::ThreadCreate [GUILDS];
403
404 /// A thread was updated (`THREAD_UPDATE`), with the cached thread before the update.
405 /// Intent: `GUILDS`.
406 ///
407 /// discord.js: `Events.ThreadUpdate` (`oldThread`, `newThread`).
408 ThreadUpdate = "threadUpdate" => payload::ThreadUpdate [GUILDS];
409
410 /// A thread was deleted (`THREAD_DELETE`), with the cached thread. Intent: `GUILDS`.
411 ///
412 /// discord.js: `Events.ThreadDelete`.
413 ThreadDelete = "threadDelete" => payload::ThreadDelete [GUILDS];
414
415 /// The bot gained access to channels: their active threads (`THREAD_LIST_SYNC`). Intent:
416 /// `GUILDS`.
417 ///
418 /// discord.js: `Events.ThreadListSync`.
419 ThreadListSync = "threadListSync" => gateway::ThreadListSync [GUILDS];
420
421 /// The bot's own thread member was updated (`THREAD_MEMBER_UPDATE`). Intent: `GUILDS`.
422 ///
423 /// The cache does not keep the bot's thread member, so there is no old one (C-091).
424 ///
425 /// discord.js: `Events.ThreadMemberUpdate`.
426 ThreadMemberUpdate = "threadMemberUpdate" => gateway::ThreadMemberUpdate [GUILDS];
427
428 /// Members were added to or removed from a thread (`THREAD_MEMBERS_UPDATE`). Intents:
429 /// `GUILDS`, and `GUILD_MEMBERS` for other users than the bot.
430 ///
431 /// discord.js: `Events.ThreadMembersUpdate`.
432 ThreadMembersUpdate = "threadMembersUpdate" => gateway::ThreadMembersUpdate [GUILDS];
433
434 // --- Guilds --------------------------------------------------------------------------
435
436 /// The bot joined a guild (`GUILD_CREATE` of a guild it was not waiting for). Intent:
437 /// `GUILDS`.
438 ///
439 /// Guilds from `READY`, and guilds back from an outage, are [`GuildAvailable`] instead
440 /// (D-223).
441 ///
442 /// discord.js: `Events.GuildCreate`.
443 GuildCreate = "guildCreate" => gateway::GuildCreate [GUILDS];
444
445 /// A guild became available (`GUILD_CREATE` of a guild from `READY` or back from an
446 /// outage). Intent: `GUILDS`.
447 ///
448 /// discord.js: `Events.GuildAvailable`.
449 GuildAvailable = "guildAvailable" => gateway::GuildCreate [GUILDS];
450
451 /// A guild was updated (`GUILD_UPDATE`), with the cached guild before the update. Intent:
452 /// `GUILDS`.
453 ///
454 /// discord.js: `Events.GuildUpdate` (`oldGuild`, `newGuild`).
455 GuildUpdate = "guildUpdate" => payload::GuildUpdate [GUILDS];
456
457 /// The bot left a guild, was removed, or the guild was deleted (`GUILD_DELETE` without
458 /// `unavailable`), with the cached guild. Intent: `GUILDS`.
459 ///
460 /// discord.js: `Events.GuildDelete`.
461 GuildDelete = "guildDelete" => payload::GuildDelete [GUILDS];
462
463 /// A guild became unavailable because of an outage (`GUILD_DELETE` with `unavailable`),
464 /// with the cached guild; [`GuildAvailable`] follows when it is back. Intent: `GUILDS`.
465 ///
466 /// discord.js: `Events.GuildUnavailable`.
467 GuildUnavailable = "guildUnavailable" => payload::GuildUnavailable [GUILDS];
468
469 /// An audit log entry was created (`GUILD_AUDIT_LOG_ENTRY_CREATE`). Intent:
470 /// `GUILD_MODERATION`, and the bot needs the `VIEW_AUDIT_LOG` permission.
471 ///
472 /// discord.js: `Events.GuildAuditLogEntryCreate`.
473 GuildAuditLogEntryCreate = "guildAuditLogEntryCreate" => gateway::GuildAuditLogEntryCreate [GUILD_MODERATION];
474
475 /// A user was banned (`GUILD_BAN_ADD`). Intent: `GUILD_MODERATION`.
476 ///
477 /// discord.js: `Events.GuildBanAdd`.
478 GuildBanAdd = "guildBanAdd" => gateway::GuildBanAdd [GUILD_MODERATION];
479
480 /// A user was unbanned (`GUILD_BAN_REMOVE`). Intent: `GUILD_MODERATION`.
481 ///
482 /// discord.js: `Events.GuildBanRemove`.
483 GuildBanRemove = "guildBanRemove" => gateway::GuildBanRemove [GUILD_MODERATION];
484
485 /// A guild's emojis changed (`GUILD_EMOJIS_UPDATE`): the full new list. Intent:
486 /// `GUILD_EXPRESSIONS`.
487 ///
488 /// With emojis in the cache, [`GuildEmojiCreate`], [`GuildEmojiUpdate`] and
489 /// [`GuildEmojiDelete`] follow for each change (D-223).
490 ///
491 /// discord.js has no such event; it only emits the per-emoji ones (C-091).
492 GuildEmojisUpdate = "guildEmojisUpdate" => gateway::GuildEmojisUpdate [GUILD_EXPRESSIONS];
493
494 /// An emoji was created, derived from [`GuildEmojisUpdate`] with emojis in the cache.
495 ///
496 /// discord.js: `Events.GuildEmojiCreate` (`emojiCreate`).
497 GuildEmojiCreate = "emojiCreate" => payload::GuildEmojiCreate [GUILD_EXPRESSIONS];
498
499 /// An emoji was updated, derived from [`GuildEmojisUpdate`] with emojis in the cache.
500 ///
501 /// discord.js: `Events.GuildEmojiUpdate` (`emojiUpdate`).
502 GuildEmojiUpdate = "emojiUpdate" => payload::GuildEmojiUpdate [GUILD_EXPRESSIONS];
503
504 /// An emoji was deleted, derived from [`GuildEmojisUpdate`] with emojis in the cache.
505 ///
506 /// discord.js: `Events.GuildEmojiDelete` (`emojiDelete`).
507 GuildEmojiDelete = "emojiDelete" => payload::GuildEmojiDelete [GUILD_EXPRESSIONS];
508
509 /// A guild's stickers changed (`GUILD_STICKERS_UPDATE`): the full new list. Intent:
510 /// `GUILD_EXPRESSIONS`.
511 ///
512 /// With stickers in the cache, [`GuildStickerCreate`], [`GuildStickerUpdate`] and
513 /// [`GuildStickerDelete`] follow for each change (D-223).
514 ///
515 /// discord.js has no such event; it only emits the per-sticker ones (C-091).
516 GuildStickersUpdate = "guildStickersUpdate" => gateway::GuildStickersUpdate [GUILD_EXPRESSIONS];
517
518 /// A sticker was created, derived from [`GuildStickersUpdate`] with stickers in the cache.
519 ///
520 /// discord.js: `Events.GuildStickerCreate` (`stickerCreate`).
521 GuildStickerCreate = "stickerCreate" => payload::GuildStickerCreate [GUILD_EXPRESSIONS];
522
523 /// A sticker was updated, derived from [`GuildStickersUpdate`] with stickers in the cache.
524 ///
525 /// discord.js: `Events.GuildStickerUpdate` (`stickerUpdate`).
526 GuildStickerUpdate = "stickerUpdate" => payload::GuildStickerUpdate [GUILD_EXPRESSIONS];
527
528 /// A sticker was deleted, derived from [`GuildStickersUpdate`] with stickers in the cache.
529 ///
530 /// discord.js: `Events.GuildStickerDelete` (`stickerDelete`).
531 GuildStickerDelete = "stickerDelete" => payload::GuildStickerDelete [GUILD_EXPRESSIONS];
532
533 /// A guild's integrations changed (`GUILD_INTEGRATIONS_UPDATE`). Intent:
534 /// `GUILD_INTEGRATIONS`.
535 ///
536 /// discord.js: `Events.GuildIntegrationsUpdate`.
537 GuildIntegrationsUpdate = "guildIntegrationsUpdate" => gateway::GuildIntegrationsUpdate [GUILD_INTEGRATIONS];
538
539 /// An integration was created (`INTEGRATION_CREATE`). Intent: `GUILD_INTEGRATIONS`.
540 ///
541 /// discord.js has no such event (C-091).
542 IntegrationCreate = "integrationCreate" => gateway::IntegrationCreate [GUILD_INTEGRATIONS];
543
544 /// An integration was updated (`INTEGRATION_UPDATE`). Intent: `GUILD_INTEGRATIONS`.
545 ///
546 /// discord.js has no such event (C-091).
547 IntegrationUpdate = "integrationUpdate" => gateway::IntegrationUpdate [GUILD_INTEGRATIONS];
548
549 /// An integration was deleted (`INTEGRATION_DELETE`). Intent: `GUILD_INTEGRATIONS`.
550 ///
551 /// discord.js has no such event (C-091).
552 IntegrationDelete = "integrationDelete" => gateway::IntegrationDelete [GUILD_INTEGRATIONS];
553
554 /// A user joined a guild (`GUILD_MEMBER_ADD`). Intent: `GUILD_MEMBERS` (privileged).
555 ///
556 /// discord.js: `Events.GuildMemberAdd`.
557 GuildMemberAdd = "guildMemberAdd" => gateway::GuildMemberAdd [GUILD_MEMBERS];
558
559 /// A member was updated (`GUILD_MEMBER_UPDATE`), with the cached member before the update.
560 /// Intent: `GUILD_MEMBERS` (privileged).
561 ///
562 /// discord.js: `Events.GuildMemberUpdate` (`oldMember`, `newMember`).
563 GuildMemberUpdate = "guildMemberUpdate" => payload::GuildMemberUpdate [GUILD_MEMBERS];
564
565 /// A user left or was removed from a guild (`GUILD_MEMBER_REMOVE`), with the cached
566 /// member. Intent: `GUILD_MEMBERS` (privileged).
567 ///
568 /// discord.js: `Events.GuildMemberRemove`.
569 GuildMemberRemove = "guildMemberRemove" => payload::GuildMemberRemove [GUILD_MEMBERS];
570
571 /// A chunk of a guild's members (`GUILD_MEMBERS_CHUNK`), the answer to a
572 /// [`RequestGuildMembers`](djs_model::gateway::payload::RequestGuildMembers) command.
573 ///
574 /// discord.js: `Events.GuildMembersChunk`.
575 GuildMembersChunk = "guildMembersChunk" => gateway::GuildMembersChunk [];
576
577 /// A role was created (`GUILD_ROLE_CREATE`). Intent: `GUILDS`.
578 ///
579 /// discord.js: `Events.GuildRoleCreate` (`roleCreate`).
580 GuildRoleCreate = "roleCreate" => gateway::GuildRoleCreate [GUILDS];
581
582 /// A role was updated (`GUILD_ROLE_UPDATE`), with the cached role before the update.
583 /// Intent: `GUILDS`.
584 ///
585 /// discord.js: `Events.GuildRoleUpdate` (`roleUpdate`; `oldRole`, `newRole`).
586 GuildRoleUpdate = "roleUpdate" => payload::GuildRoleUpdate [GUILDS];
587
588 /// A role was deleted (`GUILD_ROLE_DELETE`), with the cached role. Intent: `GUILDS`.
589 ///
590 /// discord.js: `Events.GuildRoleDelete` (`roleDelete`).
591 GuildRoleDelete = "roleDelete" => payload::GuildRoleDelete [GUILDS];
592
593 /// A scheduled event was created (`GUILD_SCHEDULED_EVENT_CREATE`). Intent:
594 /// `GUILD_SCHEDULED_EVENTS`.
595 ///
596 /// discord.js: `Events.GuildScheduledEventCreate`.
597 GuildScheduledEventCreate = "guildScheduledEventCreate"
598 => gateway::GuildScheduledEventCreate [GUILD_SCHEDULED_EVENTS];
599
600 /// A scheduled event was updated (`GUILD_SCHEDULED_EVENT_UPDATE`), with the cached event
601 /// before the update. Intent: `GUILD_SCHEDULED_EVENTS`.
602 ///
603 /// discord.js: `Events.GuildScheduledEventUpdate`.
604 GuildScheduledEventUpdate = "guildScheduledEventUpdate"
605 => payload::GuildScheduledEventUpdate [GUILD_SCHEDULED_EVENTS];
606
607 /// A scheduled event was deleted (`GUILD_SCHEDULED_EVENT_DELETE`), with the cached event.
608 /// Intent: `GUILD_SCHEDULED_EVENTS`.
609 ///
610 /// discord.js: `Events.GuildScheduledEventDelete`.
611 GuildScheduledEventDelete = "guildScheduledEventDelete"
612 => payload::GuildScheduledEventDelete [GUILD_SCHEDULED_EVENTS];
613
614 /// A user subscribed to a scheduled event (`GUILD_SCHEDULED_EVENT_USER_ADD`). Intent:
615 /// `GUILD_SCHEDULED_EVENTS`.
616 ///
617 /// discord.js: `Events.GuildScheduledEventUserAdd`.
618 GuildScheduledEventUserAdd = "guildScheduledEventUserAdd"
619 => gateway::GuildScheduledEventUserAdd [GUILD_SCHEDULED_EVENTS];
620
621 /// A user unsubscribed from a scheduled event (`GUILD_SCHEDULED_EVENT_USER_REMOVE`).
622 /// Intent: `GUILD_SCHEDULED_EVENTS`.
623 ///
624 /// discord.js: `Events.GuildScheduledEventUserRemove`.
625 GuildScheduledEventUserRemove = "guildScheduledEventUserRemove"
626 => gateway::GuildScheduledEventUserRemove [GUILD_SCHEDULED_EVENTS];
627
628 /// A soundboard sound was created (`GUILD_SOUNDBOARD_SOUND_CREATE`). Intent:
629 /// `GUILD_EXPRESSIONS`.
630 ///
631 /// discord.js: `Events.GuildSoundboardSoundCreate`.
632 GuildSoundboardSoundCreate = "guildSoundboardSoundCreate"
633 => gateway::GuildSoundboardSoundCreate [GUILD_EXPRESSIONS];
634
635 /// A soundboard sound was updated (`GUILD_SOUNDBOARD_SOUND_UPDATE`), with the cached sound
636 /// before the update. Intent: `GUILD_EXPRESSIONS`.
637 ///
638 /// discord.js: `Events.GuildSoundboardSoundUpdate`.
639 GuildSoundboardSoundUpdate = "guildSoundboardSoundUpdate"
640 => payload::GuildSoundboardSoundUpdate [GUILD_EXPRESSIONS];
641
642 /// A soundboard sound was deleted (`GUILD_SOUNDBOARD_SOUND_DELETE`), with the cached
643 /// sound. Intent: `GUILD_EXPRESSIONS`.
644 ///
645 /// discord.js: `Events.GuildSoundboardSoundDelete`.
646 GuildSoundboardSoundDelete = "guildSoundboardSoundDelete"
647 => payload::GuildSoundboardSoundDelete [GUILD_EXPRESSIONS];
648
649 /// Several soundboard sounds were updated at once (`GUILD_SOUNDBOARD_SOUNDS_UPDATE`).
650 /// Intent: `GUILD_EXPRESSIONS`.
651 ///
652 /// discord.js: `Events.GuildSoundboardSoundsUpdate`.
653 GuildSoundboardSoundsUpdate = "guildSoundboardSoundsUpdate"
654 => gateway::GuildSoundboardSoundsUpdate [GUILD_EXPRESSIONS];
655
656 /// A guild's soundboard sounds (`SOUNDBOARD_SOUNDS`), the answer to a
657 /// [`RequestSoundboardSounds`](djs_model::gateway::payload::RequestSoundboardSounds)
658 /// command.
659 ///
660 /// discord.js: `Events.SoundboardSounds`.
661 SoundboardSounds = "soundboardSounds" => gateway::SoundboardSounds [];
662
663 /// A stage instance was created (`STAGE_INSTANCE_CREATE`). Intent: `GUILDS`.
664 ///
665 /// discord.js: `Events.StageInstanceCreate`.
666 StageInstanceCreate = "stageInstanceCreate" => gateway::StageInstanceCreate [GUILDS];
667
668 /// A stage instance was updated (`STAGE_INSTANCE_UPDATE`), with the cached instance before
669 /// the update. Intent: `GUILDS`.
670 ///
671 /// discord.js: `Events.StageInstanceUpdate`.
672 StageInstanceUpdate = "stageInstanceUpdate" => payload::StageInstanceUpdate [GUILDS];
673
674 /// A stage instance was deleted (`STAGE_INSTANCE_DELETE`), with the cached instance.
675 /// Intent: `GUILDS`.
676 ///
677 /// discord.js: `Events.StageInstanceDelete`.
678 StageInstanceDelete = "stageInstanceDelete" => payload::StageInstanceDelete [GUILDS];
679
680 // --- Interactions, invites, messages -----------------------------------------------
681
682 /// A user used a command, a component or a modal (`INTERACTION_CREATE`).
683 ///
684 /// discord.js: `Events.InteractionCreate`.
685 InteractionCreate = "interactionCreate" => gateway::InteractionCreate [];
686
687 /// An invite was created (`INVITE_CREATE`). Intent: `GUILD_INVITES`.
688 ///
689 /// discord.js: `Events.InviteCreate`.
690 InviteCreate = "inviteCreate" => gateway::InviteCreate [GUILD_INVITES];
691
692 /// An invite was deleted (`INVITE_DELETE`). Intent: `GUILD_INVITES`.
693 ///
694 /// discord.js: `Events.InviteDelete`.
695 InviteDelete = "inviteDelete" => gateway::InviteDelete [GUILD_INVITES];
696
697 /// A message was sent (`MESSAGE_CREATE`). Intents: `GUILD_MESSAGES`, `DIRECT_MESSAGES`.
698 ///
699 /// Guild message content needs the privileged `MESSAGE_CONTENT` intent.
700 ///
701 /// discord.js: `Events.MessageCreate`.
702 MessageCreate = "messageCreate" => gateway::MessageCreate [GUILD_MESSAGES | DIRECT_MESSAGES];
703
704 /// A message was edited (`MESSAGE_UPDATE`), with the cached message before the edit.
705 /// Intents: `GUILD_MESSAGES`, `DIRECT_MESSAGES`.
706 ///
707 /// discord.js: `Events.MessageUpdate` (`oldMessage`, `newMessage`).
708 MessageUpdate = "messageUpdate" => payload::MessageUpdate [GUILD_MESSAGES | DIRECT_MESSAGES];
709
710 /// A message was deleted (`MESSAGE_DELETE`), with the cached message. Intents:
711 /// `GUILD_MESSAGES`, `DIRECT_MESSAGES`.
712 ///
713 /// discord.js: `Events.MessageDelete`.
714 MessageDelete = "messageDelete" => payload::MessageDelete [GUILD_MESSAGES | DIRECT_MESSAGES];
715
716 /// Messages were deleted at once (`MESSAGE_DELETE_BULK`), with the cached ones. Intent:
717 /// `GUILD_MESSAGES`.
718 ///
719 /// discord.js: `Events.MessageBulkDelete` (`messageDeleteBulk`).
720 MessageBulkDelete = "messageDeleteBulk" => payload::MessageBulkDelete [GUILD_MESSAGES];
721
722 /// A reaction was added (`MESSAGE_REACTION_ADD`). Intents: `GUILD_MESSAGE_REACTIONS`,
723 /// `DIRECT_MESSAGE_REACTIONS`.
724 ///
725 /// discord.js: `Events.MessageReactionAdd`.
726 MessageReactionAdd = "messageReactionAdd" => gateway::MessageReactionAdd [GUILD_MESSAGE_REACTIONS | DIRECT_MESSAGE_REACTIONS];
727
728 /// A reaction was removed (`MESSAGE_REACTION_REMOVE`). Intents: `GUILD_MESSAGE_REACTIONS`,
729 /// `DIRECT_MESSAGE_REACTIONS`.
730 ///
731 /// discord.js: `Events.MessageReactionRemove`.
732 MessageReactionRemove = "messageReactionRemove" => gateway::MessageReactionRemove [GUILD_MESSAGE_REACTIONS | DIRECT_MESSAGE_REACTIONS];
733
734 /// All reactions were removed from a message (`MESSAGE_REACTION_REMOVE_ALL`). Intents:
735 /// `GUILD_MESSAGE_REACTIONS`, `DIRECT_MESSAGE_REACTIONS`.
736 ///
737 /// discord.js: `Events.MessageReactionRemoveAll`.
738 MessageReactionRemoveAll = "messageReactionRemoveAll" => gateway::MessageReactionRemoveAll [GUILD_MESSAGE_REACTIONS | DIRECT_MESSAGE_REACTIONS];
739
740 /// All reactions with one emoji were removed (`MESSAGE_REACTION_REMOVE_EMOJI`). Intents:
741 /// `GUILD_MESSAGE_REACTIONS`, `DIRECT_MESSAGE_REACTIONS`.
742 ///
743 /// discord.js: `Events.MessageReactionRemoveEmoji`.
744 MessageReactionRemoveEmoji = "messageReactionRemoveEmoji"
745 => gateway::MessageReactionRemoveEmoji [GUILD_MESSAGE_REACTIONS | DIRECT_MESSAGE_REACTIONS];
746
747 /// A user voted in a poll (`MESSAGE_POLL_VOTE_ADD`). Intents: `GUILD_MESSAGE_POLLS`,
748 /// `DIRECT_MESSAGE_POLLS`.
749 ///
750 /// discord.js: `Events.MessagePollVoteAdd`.
751 MessagePollVoteAdd = "messagePollVoteAdd" => gateway::MessagePollVoteAdd [GUILD_MESSAGE_POLLS | DIRECT_MESSAGE_POLLS];
752
753 /// A user removed a poll vote (`MESSAGE_POLL_VOTE_REMOVE`). Intents: `GUILD_MESSAGE_POLLS`,
754 /// `DIRECT_MESSAGE_POLLS`.
755 ///
756 /// discord.js: `Events.MessagePollVoteRemove`.
757 MessagePollVoteRemove = "messagePollVoteRemove" => gateway::MessagePollVoteRemove [GUILD_MESSAGE_POLLS | DIRECT_MESSAGE_POLLS];
758
759 /// A user started typing (`TYPING_START`). Intents: `GUILD_MESSAGE_TYPING`,
760 /// `DIRECT_MESSAGE_TYPING`.
761 ///
762 /// discord.js: `Events.TypingStart`.
763 TypingStart = "typingStart" => gateway::TypingStart [GUILD_MESSAGE_TYPING | DIRECT_MESSAGE_TYPING];
764
765 // --- Users, presences, voice, webhooks, rate limits -------------------------------
766
767 /// A user's presence changed (`PRESENCE_UPDATE`), with the cached presence before the
768 /// change. Intent: `GUILD_PRESENCES` (privileged).
769 ///
770 /// discord.js: `Events.PresenceUpdate` (`oldPresence`, `newPresence`).
771 PresenceUpdate = "presenceUpdate" => payload::PresenceUpdate [GUILD_PRESENCES];
772
773 /// The bot's user was updated (`USER_UPDATE`), with the cached user before the update.
774 ///
775 /// discord.js: `Events.UserUpdate` (`oldUser`, `newUser`).
776 UserUpdate = "userUpdate" => payload::UserUpdate [];
777
778 /// A user joined, left or moved between voice channels, or changed their voice state
779 /// (`VOICE_STATE_UPDATE`), with the cached state before the change. Intent:
780 /// `GUILD_VOICE_STATES`.
781 ///
782 /// discord.js: `Events.VoiceStateUpdate` (`oldState`, `newState`).
783 VoiceStateUpdate = "voiceStateUpdate" => payload::VoiceStateUpdate [GUILD_VOICE_STATES];
784
785 /// The voice server of a guild the bot is connecting to (`VOICE_SERVER_UPDATE`).
786 ///
787 /// discord.js: `Events.VoiceServerUpdate`.
788 VoiceServerUpdate = "voiceServerUpdate" => gateway::VoiceServerUpdate [];
789
790 /// A user sent an effect, such as an emoji, in a voice channel
791 /// (`VOICE_CHANNEL_EFFECT_SEND`). Intent: `GUILD_VOICE_STATES`.
792 ///
793 /// discord.js: `Events.VoiceChannelEffectSend`.
794 VoiceChannelEffectSend = "voiceChannelEffectSend" => gateway::VoiceChannelEffectSend [GUILD_VOICE_STATES];
795
796 /// A voice channel's status was set or cleared (`VOICE_CHANNEL_STATUS_UPDATE`). Intent:
797 /// `GUILDS`.
798 ///
799 /// discord.js has no such event (C-091).
800 VoiceChannelStatusUpdate = "voiceChannelStatusUpdate" => gateway::VoiceChannelStatusUpdate [GUILDS];
801
802 /// A voice channel's start time changed (`VOICE_CHANNEL_START_TIME_UPDATE`). Intent:
803 /// `GUILDS`.
804 ///
805 /// discord.js has no such event (C-091).
806 VoiceChannelStartTimeUpdate = "voiceChannelStartTimeUpdate"
807 => gateway::VoiceChannelStartTimeUpdate [GUILDS];
808
809 /// A channel's webhooks changed (`WEBHOOKS_UPDATE`). Intent: `GUILD_WEBHOOKS`.
810 ///
811 /// discord.js: `Events.WebhooksUpdate`.
812 WebhooksUpdate = "webhooksUpdate" => gateway::WebhooksUpdate [GUILD_WEBHOOKS];
813
814 /// A gateway command sent by the bot was rate limited (`RATE_LIMITED`), for example a
815 /// [`RequestGuildMembers`](djs_model::gateway::payload::RequestGuildMembers).
816 ///
817 /// discord.js has no such event (C-091).
818 RateLimited = "rateLimited" => gateway::RateLimited [];
819}
820
821/// An event delivered by [`Client::events`](crate::Client::events): the shard it came from
822/// and the event.
823///
824/// discord.js counterpart: none (some discord.js events pass a `shardId` argument).
825#[derive(Clone, Debug)]
826#[non_exhaustive]
827pub struct ShardEvent {
828 /// The shard that received the event.
829 pub shard: ShardId,
830 /// The event.
831 pub event: Dispatch,
832}