djs-model 0.1.0-alpha.1

Discord API v10 types — users, guilds, channels, messages, interactions and gateway events.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
//! Guild, member, role, scheduled event, soundboard, integration, auto moderation and command
//! permission events.

use compact_str::CompactString;
use serde::{
    Deserialize, Deserializer, Serialize, Serializer,
    de::{Error as DeError, MapAccess},
};

use super::{guild_id_event, newtype_event};
use crate::{
    application_command::GuildCommandPermissions,
    audit_log::AuditLogEntry,
    auto_moderation::{Action, Rule, TriggerType},
    channel::Channel,
    emoji::Emoji,
    gateway::Presence,
    guild::{Guild, Integration, Member, MemberFlags, Role, UnavailableGuild},
    guild_scheduled_event::GuildScheduledEvent,
    id::{
        ApplicationId, AutoModerationRuleId, ChannelId, GuildId, IntegrationId, MessageId, RoleId,
        ScheduledEventId, SoundboardSoundId, UserId,
    },
    serde_util::extras::{self, Extras, Visit},
    soundboard::SoundboardSound,
    stage_instance::StageInstance,
    sticker::Sticker,
    user::{AvatarDecorationData, Collectibles, User},
    util::{ImageHash, Timestamp},
    voice::VoiceState,
};

/// The data of the [Guild Create](https://docs.discord.com/developers/events/gateway-events#guild-create)
/// dispatch event: a guild from [`Ready`](super::Ready) was loaded, became available again, or
/// the bot joined a new guild.
///
/// discord.js counterpart: the `GuildCreate` event (and the guilds becoming available).
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum GuildCreate {
    /// The guild with its members, channels, presences, ….
    Available(Box<AvailableGuild>),
    /// The guild is unavailable due to an outage.
    Unavailable(UnavailableGuild),
}

impl GuildCreate {
    /// Returns the guild's ID.
    ///
    /// discord.js counterpart: `Guild#id`.
    #[must_use]
    pub const fn id(&self) -> GuildId {
        match self {
            Self::Available(guild) => guild.guild.id,
            Self::Unavailable(guild) => guild.id,
        }
    }
}

/// An available guild in a [`GuildCreate`]: the [`Guild`] plus the state the gateway sends with
/// it (D-073).
///
/// Without the `GUILD_PRESENCES` intent, or in guilds with over 75 000 members, `members` and
/// `presences` only hold the bot and users in voice channels.
///
/// Dereferences to the contained [`Guild`].
///
/// discord.js counterpart: `GatewayGuildCreateDispatchData` (discord-api-types).
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub struct AvailableGuild {
    /// The guild.
    pub guild: Guild,
    /// When the bot joined the guild (always sent by Discord).
    pub joined_at: Option<Timestamp>,
    /// Whether the guild counts as large (offline members are not sent).
    pub large: bool,
    /// The total number of members.
    pub member_count: u32,
    /// The voice states of members in voice channels (without `guild_id`).
    pub voice_states: Vec<VoiceState>,
    /// The members sent with the guild.
    pub members: Vec<Member>,
    /// The channels.
    pub channels: Vec<Channel>,
    /// The active threads the bot can see.
    pub threads: Vec<Channel>,
    /// The presences of the members sent (without `guild_id`).
    pub presences: Vec<Presence>,
    /// The stage instances.
    pub stage_instances: Vec<StageInstance>,
    /// The scheduled events.
    pub guild_scheduled_events: Vec<GuildScheduledEvent>,
    /// The soundboard sounds.
    pub soundboard_sounds: Vec<SoundboardSound>,
}

impl core::ops::Deref for AvailableGuild {
    type Target = Guild;

    fn deref(&self) -> &Guild {
        &self.guild
    }
}

impl core::ops::DerefMut for AvailableGuild {
    fn deref_mut(&mut self) -> &mut Guild {
        &mut self.guild
    }
}

/// The `GUILD_CREATE` extras, plus the `id` and `unavailable` needed to recognize an unavailable
/// guild (whose missing fields make the [`Guild`] fail).
#[derive(Default)]
struct GuildCreateExtra {
    id: Option<GuildId>,
    unavailable: Option<bool>,
    joined_at: Option<Timestamp>,
    large: bool,
    member_count: u32,
    voice_states: Vec<VoiceState>,
    members: Vec<Member>,
    channels: Vec<Channel>,
    threads: Vec<Channel>,
    presences: Vec<Presence>,
    stage_instances: Vec<StageInstance>,
    guild_scheduled_events: Vec<GuildScheduledEvent>,
    soundboard_sounds: Vec<SoundboardSound>,
}

impl<'de> Extras<'de> for GuildCreateExtra {
    fn visit<A: MapAccess<'de>>(&mut self, key: &str, map: &mut A) -> Result<Visit, A::Error> {
        match key {
            "id" => {
                let id: GuildId = map.next_value()?;
                self.id = Some(id);
                return Ok(Visit::Replay(id.get()));
            }
            "unavailable" => self.unavailable = map.next_value()?,
            "joined_at" => self.joined_at = map.next_value()?,
            "large" => self.large = map.next_value()?,
            "member_count" => self.member_count = map.next_value()?,
            "voice_states" => self.voice_states = map.next_value()?,
            "members" => self.members = map.next_value()?,
            "channels" => self.channels = map.next_value()?,
            "threads" => self.threads = map.next_value()?,
            "presences" => self.presences = map.next_value()?,
            "stage_instances" => self.stage_instances = map.next_value()?,
            "guild_scheduled_events" => self.guild_scheduled_events = map.next_value()?,
            "soundboard_sounds" => self.soundboard_sounds = map.next_value()?,
            _ => return Ok(Visit::Pass),
        }
        Ok(Visit::Consumed)
    }

    fn recover(&self) -> bool {
        self.unavailable == Some(true) && self.id.is_some()
    }
}

impl<'de> Deserialize<'de> for GuildCreate {
    fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        let (guild, extra) = extras::deserialize::<Guild, GuildCreateExtra, D>(deserializer)?;
        let Some(guild) = guild else {
            let id = extra.id.ok_or_else(|| D::Error::missing_field("id"))?;
            return Ok(Self::Unavailable(UnavailableGuild::new(id, true)));
        };
        Ok(Self::Available(Box::new(AvailableGuild {
            guild,
            joined_at: extra.joined_at,
            large: extra.large,
            member_count: extra.member_count,
            voice_states: extra.voice_states,
            members: extra.members,
            channels: extra.channels,
            threads: extra.threads,
            presences: extra.presences,
            stage_instances: extra.stage_instances,
            guild_scheduled_events: extra.guild_scheduled_events,
            soundboard_sounds: extra.soundboard_sounds,
        })))
    }
}

impl Serialize for GuildCreate {
    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        #[derive(Serialize)]
        struct Flat<'a> {
            #[serde(flatten)]
            guild: &'a Guild,
            #[serde(skip_serializing_if = "Option::is_none")]
            joined_at: Option<Timestamp>,
            large: bool,
            member_count: u32,
            voice_states: &'a [VoiceState],
            members: &'a [Member],
            channels: &'a [Channel],
            threads: &'a [Channel],
            presences: &'a [Presence],
            stage_instances: &'a [StageInstance],
            guild_scheduled_events: &'a [GuildScheduledEvent],
            soundboard_sounds: &'a [SoundboardSound],
        }

        match self {
            Self::Available(guild) => Flat {
                guild: &guild.guild,
                joined_at: guild.joined_at,
                large: guild.large,
                member_count: guild.member_count,
                voice_states: &guild.voice_states,
                members: &guild.members,
                channels: &guild.channels,
                threads: &guild.threads,
                presences: &guild.presences,
                stage_instances: &guild.stage_instances,
                guild_scheduled_events: &guild.guild_scheduled_events,
                soundboard_sounds: &guild.soundboard_sounds,
            }
            .serialize(serializer),
            Self::Unavailable(guild) => guild.serialize(serializer),
        }
    }
}

newtype_event! {
    /// The data of the [Guild Update](https://docs.discord.com/developers/events/gateway-events#guild-update)
    /// dispatch event.
    ///
    /// discord.js counterpart: the `GuildUpdate` event.
    GuildUpdate(Guild)
}

newtype_event! {
    /// The data of the [Guild Delete](https://docs.discord.com/developers/events/gateway-events#guild-delete)
    /// dispatch event: the guild became unavailable ([`unavailable`](UnavailableGuild::unavailable)
    /// is `true`) or the bot left or was removed (`false`).
    ///
    /// discord.js counterpart: the `GuildDelete` / `GuildUnavailable` events.
    GuildDelete(UnavailableGuild)
}

newtype_event! {
    /// The data of the [Guild Audit Log Entry Create](https://docs.discord.com/developers/events/gateway-events#guild-audit-log-entry-create)
    /// dispatch event (requires `VIEW_AUDIT_LOG`); the entry's `guild_id` is set.
    ///
    /// discord.js counterpart: the `GuildAuditLogEntryCreate` event.
    GuildAuditLogEntryCreate(AuditLogEntry)
}

/// The data of the [Guild Ban Add](https://docs.discord.com/developers/events/gateway-events#guild-ban-add)
/// dispatch event (requires `BAN_MEMBERS` or `VIEW_AUDIT_LOG`).
///
/// discord.js counterpart: the `GuildBanAdd` event.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct GuildBanAdd {
    /// The guild.
    pub guild_id: GuildId,
    /// The banned user.
    pub user: User,
}

/// The data of the [Guild Ban Remove](https://docs.discord.com/developers/events/gateway-events#guild-ban-remove)
/// dispatch event (requires `BAN_MEMBERS` or `VIEW_AUDIT_LOG`).
///
/// discord.js counterpart: the `GuildBanRemove` event.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct GuildBanRemove {
    /// The guild.
    pub guild_id: GuildId,
    /// The unbanned user.
    pub user: User,
}

/// The data of the [Guild Emojis Update](https://docs.discord.com/developers/events/gateway-events#guild-emojis-update)
/// dispatch event: the guild's full emoji list.
///
/// discord.js counterpart: the `GuildEmojiCreate` / `Update` / `Delete` events (derived from it).
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct GuildEmojisUpdate {
    /// The guild.
    pub guild_id: GuildId,
    /// The guild's emojis.
    pub emojis: Vec<Emoji>,
}

/// The data of the [Guild Stickers Update](https://docs.discord.com/developers/events/gateway-events#guild-stickers-update)
/// dispatch event: the guild's full sticker list.
///
/// discord.js counterpart: the `GuildStickerCreate` / `Update` / `Delete` events (derived from
/// it).
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct GuildStickersUpdate {
    /// The guild.
    pub guild_id: GuildId,
    /// The guild's stickers.
    pub stickers: Vec<Sticker>,
}

/// The data of the [Guild Integrations Update](https://docs.discord.com/developers/events/gateway-events#guild-integrations-update)
/// dispatch event.
///
/// discord.js counterpart: the `GuildIntegrationsUpdate` event.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[non_exhaustive]
pub struct GuildIntegrationsUpdate {
    /// The guild.
    pub guild_id: GuildId,
}

guild_id_event! {
    /// The data of the [Guild Member Add](https://docs.discord.com/developers/events/gateway-events#guild-member-add)
    /// dispatch event (requires the `GUILD_MEMBERS` intent; may repeat for existing members).
    ///
    /// discord.js counterpart: the `GuildMemberAdd` event.
    GuildMemberAdd {
        /// The member.
        member: Member
    }
}

/// The data of the [Guild Member Remove](https://docs.discord.com/developers/events/gateway-events#guild-member-remove)
/// dispatch event: a user left, was kicked or banned (requires the `GUILD_MEMBERS` intent).
///
/// discord.js counterpart: the `GuildMemberRemove` event.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct GuildMemberRemove {
    /// The guild.
    pub guild_id: GuildId,
    /// The removed user.
    pub user: User,
}

/// The data of the [Guild Member Update](https://docs.discord.com/developers/events/gateway-events#guild-member-update)
/// dispatch event: a member or their user changed (requires the `GUILD_MEMBERS` intent).
///
/// Optional fields that were not sent are `None`.
///
/// discord.js counterpart: the `GuildMemberUpdate` event.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct GuildMemberUpdate {
    /// The guild.
    pub guild_id: GuildId,
    /// The member's roles.
    pub roles: Vec<RoleId>,
    /// The member's user.
    pub user: User,
    /// The nickname.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub nick: Option<CompactString>,
    /// The guild avatar hash.
    #[serde(default)]
    pub avatar: Option<ImageHash>,
    /// The guild banner hash.
    #[serde(default)]
    pub banner: Option<ImageHash>,
    /// When the user joined (`None` for some guest members).
    #[serde(default)]
    pub joined_at: Option<Timestamp>,
    /// When the member started boosting.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub premium_since: Option<Timestamp>,
    /// Whether the member is server-deafened.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub deaf: Option<bool>,
    /// Whether the member is server-muted.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub mute: Option<bool>,
    /// Whether the member has not passed membership screening yet.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub pending: Option<bool>,
    /// When the member's timeout ends.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub communication_disabled_until: Option<Timestamp>,
    /// The member's flags.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub flags: Option<MemberFlags>,
    /// The guild avatar decoration.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub avatar_decoration_data: Option<Box<AvatarDecorationData>>,
    /// The guild collectibles.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub collectibles: Option<Box<Collectibles>>,
}

/// The data of the [Guild Members Chunk](https://docs.discord.com/developers/events/gateway-events#guild-members-chunk)
/// dispatch event: one part of the answer to a
/// [`RequestGuildMembers`](crate::gateway::payload::RequestGuildMembers) command.
///
/// discord.js counterpart: the `GuildMembersChunk` event.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct GuildMembersChunk {
    /// The guild.
    pub guild_id: GuildId,
    /// The members in this chunk.
    pub members: Vec<Member>,
    /// This chunk's index (`0 ≤ chunk_index < chunk_count`).
    pub chunk_index: u32,
    /// The number of chunks of the answer.
    pub chunk_count: u32,
    /// The requested IDs that are not members.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub not_found: Vec<UserId>,
    /// The members' presences (if requested).
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub presences: Vec<Presence>,
    /// The request's nonce.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub nonce: Option<CompactString>,
}

/// The data of the [Guild Role Create](https://docs.discord.com/developers/events/gateway-events#guild-role-create)
/// dispatch event.
///
/// discord.js counterpart: the `GuildRoleCreate` event.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct GuildRoleCreate {
    /// The guild.
    pub guild_id: GuildId,
    /// The created role.
    pub role: Role,
}

/// The data of the [Guild Role Update](https://docs.discord.com/developers/events/gateway-events#guild-role-update)
/// dispatch event.
///
/// discord.js counterpart: the `GuildRoleUpdate` event.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct GuildRoleUpdate {
    /// The guild.
    pub guild_id: GuildId,
    /// The updated role.
    pub role: Role,
}

/// The data of the [Guild Role Delete](https://docs.discord.com/developers/events/gateway-events#guild-role-delete)
/// dispatch event.
///
/// discord.js counterpart: the `GuildRoleDelete` event.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[non_exhaustive]
pub struct GuildRoleDelete {
    /// The guild.
    pub guild_id: GuildId,
    /// The deleted role.
    pub role_id: RoleId,
}

newtype_event! {
    /// The data of the [Guild Scheduled Event Create](https://docs.discord.com/developers/events/gateway-events#guild-scheduled-event-create)
    /// dispatch event.
    ///
    /// discord.js counterpart: the `GuildScheduledEventCreate` event.
    GuildScheduledEventCreate(GuildScheduledEvent)
}

newtype_event! {
    /// The data of the [Guild Scheduled Event Update](https://docs.discord.com/developers/events/gateway-events#guild-scheduled-event-update)
    /// dispatch event.
    ///
    /// discord.js counterpart: the `GuildScheduledEventUpdate` event.
    GuildScheduledEventUpdate(GuildScheduledEvent)
}

newtype_event! {
    /// The data of the [Guild Scheduled Event Delete](https://docs.discord.com/developers/events/gateway-events#guild-scheduled-event-delete)
    /// dispatch event.
    ///
    /// discord.js counterpart: the `GuildScheduledEventDelete` event.
    GuildScheduledEventDelete(GuildScheduledEvent)
}

/// The data of the [Guild Scheduled Event User Add](https://docs.discord.com/developers/events/gateway-events#guild-scheduled-event-user-add)
/// dispatch event: a user subscribed to an event.
///
/// discord.js counterpart: the `GuildScheduledEventUserAdd` event.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[non_exhaustive]
pub struct GuildScheduledEventUserAdd {
    /// The scheduled event.
    pub guild_scheduled_event_id: ScheduledEventId,
    /// The user.
    pub user_id: UserId,
    /// The guild.
    pub guild_id: GuildId,
}

/// The data of the [Guild Scheduled Event User Remove](https://docs.discord.com/developers/events/gateway-events#guild-scheduled-event-user-remove)
/// dispatch event: a user unsubscribed from an event.
///
/// discord.js counterpart: the `GuildScheduledEventUserRemove` event.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[non_exhaustive]
pub struct GuildScheduledEventUserRemove {
    /// The scheduled event.
    pub guild_scheduled_event_id: ScheduledEventId,
    /// The user.
    pub user_id: UserId,
    /// The guild.
    pub guild_id: GuildId,
}

newtype_event! {
    /// The data of the [Guild Soundboard Sound Create](https://docs.discord.com/developers/events/gateway-events#guild-soundboard-sound-create)
    /// dispatch event.
    ///
    /// discord.js counterpart: the `GuildSoundboardSoundCreate` event.
    GuildSoundboardSoundCreate(SoundboardSound)
}

newtype_event! {
    /// The data of the [Guild Soundboard Sound Update](https://docs.discord.com/developers/events/gateway-events#guild-soundboard-sound-update)
    /// dispatch event.
    ///
    /// discord.js counterpart: the `GuildSoundboardSoundUpdate` event.
    GuildSoundboardSoundUpdate(SoundboardSound)
}

/// The data of the [Guild Soundboard Sound Delete](https://docs.discord.com/developers/events/gateway-events#guild-soundboard-sound-delete)
/// dispatch event.
///
/// discord.js counterpart: the `GuildSoundboardSoundDelete` event.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[non_exhaustive]
pub struct GuildSoundboardSoundDelete {
    /// The deleted sound.
    pub sound_id: SoundboardSoundId,
    /// The guild.
    pub guild_id: GuildId,
}

/// The data of the [Guild Soundboard Sounds Update](https://docs.discord.com/developers/events/gateway-events#guild-soundboard-sounds-update)
/// dispatch event: several sounds changed.
///
/// discord.js counterpart: the `GuildSoundboardSoundsUpdate` event.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct GuildSoundboardSoundsUpdate {
    /// The guild's sounds.
    pub soundboard_sounds: Vec<SoundboardSound>,
    /// The guild.
    pub guild_id: GuildId,
}

/// The data of the [Soundboard Sounds](https://docs.discord.com/developers/events/gateway-events#soundboard-sounds)
/// dispatch event: a guild's sounds, sent in response to a
/// [`RequestSoundboardSounds`](crate::gateway::payload::RequestSoundboardSounds) command.
///
/// discord.js counterpart: the `SoundboardSounds` event.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct SoundboardSounds {
    /// The guild's sounds.
    pub soundboard_sounds: Vec<SoundboardSound>,
    /// The guild.
    pub guild_id: GuildId,
}

guild_id_event! {
    /// The data of the [Integration Create](https://docs.discord.com/developers/events/gateway-events#integration-create)
    /// dispatch event (the integration has no `user`).
    ///
    /// discord.js counterpart: the integration data behind `GuildIntegrationsUpdate`.
    IntegrationCreate {
        /// The created integration.
        integration: Integration
    }
}

guild_id_event! {
    /// The data of the [Integration Update](https://docs.discord.com/developers/events/gateway-events#integration-update)
    /// dispatch event (the integration has no `user`).
    ///
    /// discord.js counterpart: the integration data behind `GuildIntegrationsUpdate`.
    IntegrationUpdate {
        /// The updated integration.
        integration: Integration
    }
}

/// The data of the [Integration Delete](https://docs.discord.com/developers/events/gateway-events#integration-delete)
/// dispatch event.
///
/// discord.js counterpart: `GatewayIntegrationDeleteDispatchData` (discord-api-types).
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[non_exhaustive]
pub struct IntegrationDelete {
    /// The deleted integration.
    pub id: IntegrationId,
    /// The guild.
    pub guild_id: GuildId,
    /// The bot or `OAuth2` application of a Discord integration.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub application_id: Option<ApplicationId>,
}

newtype_event! {
    /// The data of the [Auto Moderation Rule Create](https://docs.discord.com/developers/events/gateway-events#auto-moderation-rule-create)
    /// dispatch event (requires `MANAGE_GUILD`).
    ///
    /// discord.js counterpart: the `AutoModerationRuleCreate` event.
    AutoModerationRuleCreate(Rule)
}

newtype_event! {
    /// The data of the [Auto Moderation Rule Update](https://docs.discord.com/developers/events/gateway-events#auto-moderation-rule-update)
    /// dispatch event (requires `MANAGE_GUILD`).
    ///
    /// discord.js counterpart: the `AutoModerationRuleUpdate` event.
    AutoModerationRuleUpdate(Rule)
}

newtype_event! {
    /// The data of the [Auto Moderation Rule Delete](https://docs.discord.com/developers/events/gateway-events#auto-moderation-rule-delete)
    /// dispatch event (requires `MANAGE_GUILD`).
    ///
    /// discord.js counterpart: the `AutoModerationRuleDelete` event.
    AutoModerationRuleDelete(Rule)
}

/// The data of the [Auto Moderation Action Execution](https://docs.discord.com/developers/events/gateway-events#auto-moderation-action-execution)
/// dispatch event: a rule triggered and one of its actions ran (requires `MANAGE_GUILD`; the
/// content fields require the `MESSAGE_CONTENT` intent).
///
/// discord.js counterpart: the `AutoModerationActionExecution` event.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct AutoModerationActionExecution {
    /// The guild.
    pub guild_id: GuildId,
    /// The action that ran.
    pub action: Action,
    /// The rule.
    pub rule_id: AutoModerationRuleId,
    /// The rule's trigger type.
    pub rule_trigger_type: TriggerType,
    /// The user whose content triggered the rule.
    pub user_id: UserId,
    /// The channel the content was posted in.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub channel_id: Option<ChannelId>,
    /// The user's message (absent if it was blocked or the content was not a message).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub message_id: Option<MessageId>,
    /// The alert message posted by a `SEND_ALERT_MESSAGE` action.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub alert_system_message_id: Option<MessageId>,
    /// The user's content (empty without the `MESSAGE_CONTENT` intent).
    #[serde(default)]
    pub content: CompactString,
    /// The keyword or phrase of the rule that matched.
    #[serde(default)]
    pub matched_keyword: Option<CompactString>,
    /// The part of the content that matched (`None` without the `MESSAGE_CONTENT` intent).
    #[serde(default)]
    pub matched_content: Option<CompactString>,
}

newtype_event! {
    /// The data of the [Application Command Permissions Update](https://docs.discord.com/developers/events/gateway-events#application-command-permissions-update)
    /// dispatch event.
    ///
    /// discord.js counterpart: the `ApplicationCommandPermissionsUpdate` event.
    ApplicationCommandPermissionsUpdate(GuildCommandPermissions)
}