Skip to main content

djs_model/gateway/payload/incoming/
guild.rs

1//! Guild, member, role, scheduled event, soundboard, integration, auto moderation and command
2//! permission events.
3
4use compact_str::CompactString;
5use serde::{
6    Deserialize, Deserializer, Serialize, Serializer,
7    de::{Error as DeError, MapAccess},
8};
9
10use super::{guild_id_event, newtype_event};
11use crate::{
12    application_command::GuildCommandPermissions,
13    audit_log::AuditLogEntry,
14    auto_moderation::{Action, Rule, TriggerType},
15    channel::Channel,
16    emoji::Emoji,
17    gateway::Presence,
18    guild::{Guild, Integration, Member, MemberFlags, Role, UnavailableGuild},
19    guild_scheduled_event::GuildScheduledEvent,
20    id::{
21        ApplicationId, AutoModerationRuleId, ChannelId, GuildId, IntegrationId, MessageId, RoleId,
22        ScheduledEventId, SoundboardSoundId, UserId,
23    },
24    serde_util::extras::{self, Extras, Visit},
25    soundboard::SoundboardSound,
26    stage_instance::StageInstance,
27    sticker::Sticker,
28    user::{AvatarDecorationData, Collectibles, User},
29    util::{ImageHash, Timestamp},
30    voice::VoiceState,
31};
32
33/// The data of the [Guild Create](https://docs.discord.com/developers/events/gateway-events#guild-create)
34/// dispatch event: a guild from [`Ready`](super::Ready) was loaded, became available again, or
35/// the bot joined a new guild.
36///
37/// discord.js counterpart: the `GuildCreate` event (and the guilds becoming available).
38#[derive(Clone, Debug, PartialEq)]
39#[non_exhaustive]
40pub enum GuildCreate {
41    /// The guild with its members, channels, presences, ….
42    Available(Box<AvailableGuild>),
43    /// The guild is unavailable due to an outage.
44    Unavailable(UnavailableGuild),
45}
46
47impl GuildCreate {
48    /// Returns the guild's ID.
49    ///
50    /// discord.js counterpart: `Guild#id`.
51    #[must_use]
52    pub const fn id(&self) -> GuildId {
53        match self {
54            Self::Available(guild) => guild.guild.id,
55            Self::Unavailable(guild) => guild.id,
56        }
57    }
58}
59
60/// An available guild in a [`GuildCreate`]: the [`Guild`] plus the state the gateway sends with
61/// it (D-073).
62///
63/// Without the `GUILD_PRESENCES` intent, or in guilds with over 75 000 members, `members` and
64/// `presences` only hold the bot and users in voice channels.
65///
66/// Dereferences to the contained [`Guild`].
67///
68/// discord.js counterpart: `GatewayGuildCreateDispatchData` (discord-api-types).
69#[derive(Clone, Debug, PartialEq)]
70#[non_exhaustive]
71pub struct AvailableGuild {
72    /// The guild.
73    pub guild: Guild,
74    /// When the bot joined the guild (always sent by Discord).
75    pub joined_at: Option<Timestamp>,
76    /// Whether the guild counts as large (offline members are not sent).
77    pub large: bool,
78    /// The total number of members.
79    pub member_count: u32,
80    /// The voice states of members in voice channels (without `guild_id`).
81    pub voice_states: Vec<VoiceState>,
82    /// The members sent with the guild.
83    pub members: Vec<Member>,
84    /// The channels.
85    pub channels: Vec<Channel>,
86    /// The active threads the bot can see.
87    pub threads: Vec<Channel>,
88    /// The presences of the members sent (without `guild_id`).
89    pub presences: Vec<Presence>,
90    /// The stage instances.
91    pub stage_instances: Vec<StageInstance>,
92    /// The scheduled events.
93    pub guild_scheduled_events: Vec<GuildScheduledEvent>,
94    /// The soundboard sounds.
95    pub soundboard_sounds: Vec<SoundboardSound>,
96}
97
98impl core::ops::Deref for AvailableGuild {
99    type Target = Guild;
100
101    fn deref(&self) -> &Guild {
102        &self.guild
103    }
104}
105
106impl core::ops::DerefMut for AvailableGuild {
107    fn deref_mut(&mut self) -> &mut Guild {
108        &mut self.guild
109    }
110}
111
112/// The `GUILD_CREATE` extras, plus the `id` and `unavailable` needed to recognize an unavailable
113/// guild (whose missing fields make the [`Guild`] fail).
114#[derive(Default)]
115struct GuildCreateExtra {
116    id: Option<GuildId>,
117    unavailable: Option<bool>,
118    joined_at: Option<Timestamp>,
119    large: bool,
120    member_count: u32,
121    voice_states: Vec<VoiceState>,
122    members: Vec<Member>,
123    channels: Vec<Channel>,
124    threads: Vec<Channel>,
125    presences: Vec<Presence>,
126    stage_instances: Vec<StageInstance>,
127    guild_scheduled_events: Vec<GuildScheduledEvent>,
128    soundboard_sounds: Vec<SoundboardSound>,
129}
130
131impl<'de> Extras<'de> for GuildCreateExtra {
132    fn visit<A: MapAccess<'de>>(&mut self, key: &str, map: &mut A) -> Result<Visit, A::Error> {
133        match key {
134            "id" => {
135                let id: GuildId = map.next_value()?;
136                self.id = Some(id);
137                return Ok(Visit::Replay(id.get()));
138            }
139            "unavailable" => self.unavailable = map.next_value()?,
140            "joined_at" => self.joined_at = map.next_value()?,
141            "large" => self.large = map.next_value()?,
142            "member_count" => self.member_count = map.next_value()?,
143            "voice_states" => self.voice_states = map.next_value()?,
144            "members" => self.members = map.next_value()?,
145            "channels" => self.channels = map.next_value()?,
146            "threads" => self.threads = map.next_value()?,
147            "presences" => self.presences = map.next_value()?,
148            "stage_instances" => self.stage_instances = map.next_value()?,
149            "guild_scheduled_events" => self.guild_scheduled_events = map.next_value()?,
150            "soundboard_sounds" => self.soundboard_sounds = map.next_value()?,
151            _ => return Ok(Visit::Pass),
152        }
153        Ok(Visit::Consumed)
154    }
155
156    fn recover(&self) -> bool {
157        self.unavailable == Some(true) && self.id.is_some()
158    }
159}
160
161impl<'de> Deserialize<'de> for GuildCreate {
162    fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
163        let (guild, extra) = extras::deserialize::<Guild, GuildCreateExtra, D>(deserializer)?;
164        let Some(guild) = guild else {
165            let id = extra.id.ok_or_else(|| D::Error::missing_field("id"))?;
166            return Ok(Self::Unavailable(UnavailableGuild::new(id, true)));
167        };
168        Ok(Self::Available(Box::new(AvailableGuild {
169            guild,
170            joined_at: extra.joined_at,
171            large: extra.large,
172            member_count: extra.member_count,
173            voice_states: extra.voice_states,
174            members: extra.members,
175            channels: extra.channels,
176            threads: extra.threads,
177            presences: extra.presences,
178            stage_instances: extra.stage_instances,
179            guild_scheduled_events: extra.guild_scheduled_events,
180            soundboard_sounds: extra.soundboard_sounds,
181        })))
182    }
183}
184
185impl Serialize for GuildCreate {
186    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
187        #[derive(Serialize)]
188        struct Flat<'a> {
189            #[serde(flatten)]
190            guild: &'a Guild,
191            #[serde(skip_serializing_if = "Option::is_none")]
192            joined_at: Option<Timestamp>,
193            large: bool,
194            member_count: u32,
195            voice_states: &'a [VoiceState],
196            members: &'a [Member],
197            channels: &'a [Channel],
198            threads: &'a [Channel],
199            presences: &'a [Presence],
200            stage_instances: &'a [StageInstance],
201            guild_scheduled_events: &'a [GuildScheduledEvent],
202            soundboard_sounds: &'a [SoundboardSound],
203        }
204
205        match self {
206            Self::Available(guild) => Flat {
207                guild: &guild.guild,
208                joined_at: guild.joined_at,
209                large: guild.large,
210                member_count: guild.member_count,
211                voice_states: &guild.voice_states,
212                members: &guild.members,
213                channels: &guild.channels,
214                threads: &guild.threads,
215                presences: &guild.presences,
216                stage_instances: &guild.stage_instances,
217                guild_scheduled_events: &guild.guild_scheduled_events,
218                soundboard_sounds: &guild.soundboard_sounds,
219            }
220            .serialize(serializer),
221            Self::Unavailable(guild) => guild.serialize(serializer),
222        }
223    }
224}
225
226newtype_event! {
227    /// The data of the [Guild Update](https://docs.discord.com/developers/events/gateway-events#guild-update)
228    /// dispatch event.
229    ///
230    /// discord.js counterpart: the `GuildUpdate` event.
231    GuildUpdate(Guild)
232}
233
234newtype_event! {
235    /// The data of the [Guild Delete](https://docs.discord.com/developers/events/gateway-events#guild-delete)
236    /// dispatch event: the guild became unavailable ([`unavailable`](UnavailableGuild::unavailable)
237    /// is `true`) or the bot left or was removed (`false`).
238    ///
239    /// discord.js counterpart: the `GuildDelete` / `GuildUnavailable` events.
240    GuildDelete(UnavailableGuild)
241}
242
243newtype_event! {
244    /// The data of the [Guild Audit Log Entry Create](https://docs.discord.com/developers/events/gateway-events#guild-audit-log-entry-create)
245    /// dispatch event (requires `VIEW_AUDIT_LOG`); the entry's `guild_id` is set.
246    ///
247    /// discord.js counterpart: the `GuildAuditLogEntryCreate` event.
248    GuildAuditLogEntryCreate(AuditLogEntry)
249}
250
251/// The data of the [Guild Ban Add](https://docs.discord.com/developers/events/gateway-events#guild-ban-add)
252/// dispatch event (requires `BAN_MEMBERS` or `VIEW_AUDIT_LOG`).
253///
254/// discord.js counterpart: the `GuildBanAdd` event.
255#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
256#[non_exhaustive]
257pub struct GuildBanAdd {
258    /// The guild.
259    pub guild_id: GuildId,
260    /// The banned user.
261    pub user: User,
262}
263
264/// The data of the [Guild Ban Remove](https://docs.discord.com/developers/events/gateway-events#guild-ban-remove)
265/// dispatch event (requires `BAN_MEMBERS` or `VIEW_AUDIT_LOG`).
266///
267/// discord.js counterpart: the `GuildBanRemove` event.
268#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
269#[non_exhaustive]
270pub struct GuildBanRemove {
271    /// The guild.
272    pub guild_id: GuildId,
273    /// The unbanned user.
274    pub user: User,
275}
276
277/// The data of the [Guild Emojis Update](https://docs.discord.com/developers/events/gateway-events#guild-emojis-update)
278/// dispatch event: the guild's full emoji list.
279///
280/// discord.js counterpart: the `GuildEmojiCreate` / `Update` / `Delete` events (derived from it).
281#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
282#[non_exhaustive]
283pub struct GuildEmojisUpdate {
284    /// The guild.
285    pub guild_id: GuildId,
286    /// The guild's emojis.
287    pub emojis: Vec<Emoji>,
288}
289
290/// The data of the [Guild Stickers Update](https://docs.discord.com/developers/events/gateway-events#guild-stickers-update)
291/// dispatch event: the guild's full sticker list.
292///
293/// discord.js counterpart: the `GuildStickerCreate` / `Update` / `Delete` events (derived from
294/// it).
295#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
296#[non_exhaustive]
297pub struct GuildStickersUpdate {
298    /// The guild.
299    pub guild_id: GuildId,
300    /// The guild's stickers.
301    pub stickers: Vec<Sticker>,
302}
303
304/// The data of the [Guild Integrations Update](https://docs.discord.com/developers/events/gateway-events#guild-integrations-update)
305/// dispatch event.
306///
307/// discord.js counterpart: the `GuildIntegrationsUpdate` event.
308#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
309#[non_exhaustive]
310pub struct GuildIntegrationsUpdate {
311    /// The guild.
312    pub guild_id: GuildId,
313}
314
315guild_id_event! {
316    /// The data of the [Guild Member Add](https://docs.discord.com/developers/events/gateway-events#guild-member-add)
317    /// dispatch event (requires the `GUILD_MEMBERS` intent; may repeat for existing members).
318    ///
319    /// discord.js counterpart: the `GuildMemberAdd` event.
320    GuildMemberAdd {
321        /// The member.
322        member: Member
323    }
324}
325
326/// The data of the [Guild Member Remove](https://docs.discord.com/developers/events/gateway-events#guild-member-remove)
327/// dispatch event: a user left, was kicked or banned (requires the `GUILD_MEMBERS` intent).
328///
329/// discord.js counterpart: the `GuildMemberRemove` event.
330#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
331#[non_exhaustive]
332pub struct GuildMemberRemove {
333    /// The guild.
334    pub guild_id: GuildId,
335    /// The removed user.
336    pub user: User,
337}
338
339/// The data of the [Guild Member Update](https://docs.discord.com/developers/events/gateway-events#guild-member-update)
340/// dispatch event: a member or their user changed (requires the `GUILD_MEMBERS` intent).
341///
342/// Optional fields that were not sent are `None`.
343///
344/// discord.js counterpart: the `GuildMemberUpdate` event.
345#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
346#[non_exhaustive]
347pub struct GuildMemberUpdate {
348    /// The guild.
349    pub guild_id: GuildId,
350    /// The member's roles.
351    pub roles: Vec<RoleId>,
352    /// The member's user.
353    pub user: User,
354    /// The nickname.
355    #[serde(default, skip_serializing_if = "Option::is_none")]
356    pub nick: Option<CompactString>,
357    /// The guild avatar hash.
358    #[serde(default)]
359    pub avatar: Option<ImageHash>,
360    /// The guild banner hash.
361    #[serde(default)]
362    pub banner: Option<ImageHash>,
363    /// When the user joined (`None` for some guest members).
364    #[serde(default)]
365    pub joined_at: Option<Timestamp>,
366    /// When the member started boosting.
367    #[serde(default, skip_serializing_if = "Option::is_none")]
368    pub premium_since: Option<Timestamp>,
369    /// Whether the member is server-deafened.
370    #[serde(default, skip_serializing_if = "Option::is_none")]
371    pub deaf: Option<bool>,
372    /// Whether the member is server-muted.
373    #[serde(default, skip_serializing_if = "Option::is_none")]
374    pub mute: Option<bool>,
375    /// Whether the member has not passed membership screening yet.
376    #[serde(default, skip_serializing_if = "Option::is_none")]
377    pub pending: Option<bool>,
378    /// When the member's timeout ends.
379    #[serde(default, skip_serializing_if = "Option::is_none")]
380    pub communication_disabled_until: Option<Timestamp>,
381    /// The member's flags.
382    #[serde(default, skip_serializing_if = "Option::is_none")]
383    pub flags: Option<MemberFlags>,
384    /// The guild avatar decoration.
385    #[serde(default, skip_serializing_if = "Option::is_none")]
386    pub avatar_decoration_data: Option<Box<AvatarDecorationData>>,
387    /// The guild collectibles.
388    #[serde(default, skip_serializing_if = "Option::is_none")]
389    pub collectibles: Option<Box<Collectibles>>,
390}
391
392/// The data of the [Guild Members Chunk](https://docs.discord.com/developers/events/gateway-events#guild-members-chunk)
393/// dispatch event: one part of the answer to a
394/// [`RequestGuildMembers`](crate::gateway::payload::RequestGuildMembers) command.
395///
396/// discord.js counterpart: the `GuildMembersChunk` event.
397#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
398#[non_exhaustive]
399pub struct GuildMembersChunk {
400    /// The guild.
401    pub guild_id: GuildId,
402    /// The members in this chunk.
403    pub members: Vec<Member>,
404    /// This chunk's index (`0 ≤ chunk_index < chunk_count`).
405    pub chunk_index: u32,
406    /// The number of chunks of the answer.
407    pub chunk_count: u32,
408    /// The requested IDs that are not members.
409    #[serde(default, skip_serializing_if = "Vec::is_empty")]
410    pub not_found: Vec<UserId>,
411    /// The members' presences (if requested).
412    #[serde(default, skip_serializing_if = "Vec::is_empty")]
413    pub presences: Vec<Presence>,
414    /// The request's nonce.
415    #[serde(default, skip_serializing_if = "Option::is_none")]
416    pub nonce: Option<CompactString>,
417}
418
419/// The data of the [Guild Role Create](https://docs.discord.com/developers/events/gateway-events#guild-role-create)
420/// dispatch event.
421///
422/// discord.js counterpart: the `GuildRoleCreate` event.
423#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
424#[non_exhaustive]
425pub struct GuildRoleCreate {
426    /// The guild.
427    pub guild_id: GuildId,
428    /// The created role.
429    pub role: Role,
430}
431
432/// The data of the [Guild Role Update](https://docs.discord.com/developers/events/gateway-events#guild-role-update)
433/// dispatch event.
434///
435/// discord.js counterpart: the `GuildRoleUpdate` event.
436#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
437#[non_exhaustive]
438pub struct GuildRoleUpdate {
439    /// The guild.
440    pub guild_id: GuildId,
441    /// The updated role.
442    pub role: Role,
443}
444
445/// The data of the [Guild Role Delete](https://docs.discord.com/developers/events/gateway-events#guild-role-delete)
446/// dispatch event.
447///
448/// discord.js counterpart: the `GuildRoleDelete` event.
449#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
450#[non_exhaustive]
451pub struct GuildRoleDelete {
452    /// The guild.
453    pub guild_id: GuildId,
454    /// The deleted role.
455    pub role_id: RoleId,
456}
457
458newtype_event! {
459    /// The data of the [Guild Scheduled Event Create](https://docs.discord.com/developers/events/gateway-events#guild-scheduled-event-create)
460    /// dispatch event.
461    ///
462    /// discord.js counterpart: the `GuildScheduledEventCreate` event.
463    GuildScheduledEventCreate(GuildScheduledEvent)
464}
465
466newtype_event! {
467    /// The data of the [Guild Scheduled Event Update](https://docs.discord.com/developers/events/gateway-events#guild-scheduled-event-update)
468    /// dispatch event.
469    ///
470    /// discord.js counterpart: the `GuildScheduledEventUpdate` event.
471    GuildScheduledEventUpdate(GuildScheduledEvent)
472}
473
474newtype_event! {
475    /// The data of the [Guild Scheduled Event Delete](https://docs.discord.com/developers/events/gateway-events#guild-scheduled-event-delete)
476    /// dispatch event.
477    ///
478    /// discord.js counterpart: the `GuildScheduledEventDelete` event.
479    GuildScheduledEventDelete(GuildScheduledEvent)
480}
481
482/// The data of the [Guild Scheduled Event User Add](https://docs.discord.com/developers/events/gateway-events#guild-scheduled-event-user-add)
483/// dispatch event: a user subscribed to an event.
484///
485/// discord.js counterpart: the `GuildScheduledEventUserAdd` event.
486#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
487#[non_exhaustive]
488pub struct GuildScheduledEventUserAdd {
489    /// The scheduled event.
490    pub guild_scheduled_event_id: ScheduledEventId,
491    /// The user.
492    pub user_id: UserId,
493    /// The guild.
494    pub guild_id: GuildId,
495}
496
497/// The data of the [Guild Scheduled Event User Remove](https://docs.discord.com/developers/events/gateway-events#guild-scheduled-event-user-remove)
498/// dispatch event: a user unsubscribed from an event.
499///
500/// discord.js counterpart: the `GuildScheduledEventUserRemove` event.
501#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
502#[non_exhaustive]
503pub struct GuildScheduledEventUserRemove {
504    /// The scheduled event.
505    pub guild_scheduled_event_id: ScheduledEventId,
506    /// The user.
507    pub user_id: UserId,
508    /// The guild.
509    pub guild_id: GuildId,
510}
511
512newtype_event! {
513    /// The data of the [Guild Soundboard Sound Create](https://docs.discord.com/developers/events/gateway-events#guild-soundboard-sound-create)
514    /// dispatch event.
515    ///
516    /// discord.js counterpart: the `GuildSoundboardSoundCreate` event.
517    GuildSoundboardSoundCreate(SoundboardSound)
518}
519
520newtype_event! {
521    /// The data of the [Guild Soundboard Sound Update](https://docs.discord.com/developers/events/gateway-events#guild-soundboard-sound-update)
522    /// dispatch event.
523    ///
524    /// discord.js counterpart: the `GuildSoundboardSoundUpdate` event.
525    GuildSoundboardSoundUpdate(SoundboardSound)
526}
527
528/// The data of the [Guild Soundboard Sound Delete](https://docs.discord.com/developers/events/gateway-events#guild-soundboard-sound-delete)
529/// dispatch event.
530///
531/// discord.js counterpart: the `GuildSoundboardSoundDelete` event.
532#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
533#[non_exhaustive]
534pub struct GuildSoundboardSoundDelete {
535    /// The deleted sound.
536    pub sound_id: SoundboardSoundId,
537    /// The guild.
538    pub guild_id: GuildId,
539}
540
541/// The data of the [Guild Soundboard Sounds Update](https://docs.discord.com/developers/events/gateway-events#guild-soundboard-sounds-update)
542/// dispatch event: several sounds changed.
543///
544/// discord.js counterpart: the `GuildSoundboardSoundsUpdate` event.
545#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
546#[non_exhaustive]
547pub struct GuildSoundboardSoundsUpdate {
548    /// The guild's sounds.
549    pub soundboard_sounds: Vec<SoundboardSound>,
550    /// The guild.
551    pub guild_id: GuildId,
552}
553
554/// The data of the [Soundboard Sounds](https://docs.discord.com/developers/events/gateway-events#soundboard-sounds)
555/// dispatch event: a guild's sounds, sent in response to a
556/// [`RequestSoundboardSounds`](crate::gateway::payload::RequestSoundboardSounds) command.
557///
558/// discord.js counterpart: the `SoundboardSounds` event.
559#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
560#[non_exhaustive]
561pub struct SoundboardSounds {
562    /// The guild's sounds.
563    pub soundboard_sounds: Vec<SoundboardSound>,
564    /// The guild.
565    pub guild_id: GuildId,
566}
567
568guild_id_event! {
569    /// The data of the [Integration Create](https://docs.discord.com/developers/events/gateway-events#integration-create)
570    /// dispatch event (the integration has no `user`).
571    ///
572    /// discord.js counterpart: the integration data behind `GuildIntegrationsUpdate`.
573    IntegrationCreate {
574        /// The created integration.
575        integration: Integration
576    }
577}
578
579guild_id_event! {
580    /// The data of the [Integration Update](https://docs.discord.com/developers/events/gateway-events#integration-update)
581    /// dispatch event (the integration has no `user`).
582    ///
583    /// discord.js counterpart: the integration data behind `GuildIntegrationsUpdate`.
584    IntegrationUpdate {
585        /// The updated integration.
586        integration: Integration
587    }
588}
589
590/// The data of the [Integration Delete](https://docs.discord.com/developers/events/gateway-events#integration-delete)
591/// dispatch event.
592///
593/// discord.js counterpart: `GatewayIntegrationDeleteDispatchData` (discord-api-types).
594#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
595#[non_exhaustive]
596pub struct IntegrationDelete {
597    /// The deleted integration.
598    pub id: IntegrationId,
599    /// The guild.
600    pub guild_id: GuildId,
601    /// The bot or `OAuth2` application of a Discord integration.
602    #[serde(default, skip_serializing_if = "Option::is_none")]
603    pub application_id: Option<ApplicationId>,
604}
605
606newtype_event! {
607    /// The data of the [Auto Moderation Rule Create](https://docs.discord.com/developers/events/gateway-events#auto-moderation-rule-create)
608    /// dispatch event (requires `MANAGE_GUILD`).
609    ///
610    /// discord.js counterpart: the `AutoModerationRuleCreate` event.
611    AutoModerationRuleCreate(Rule)
612}
613
614newtype_event! {
615    /// The data of the [Auto Moderation Rule Update](https://docs.discord.com/developers/events/gateway-events#auto-moderation-rule-update)
616    /// dispatch event (requires `MANAGE_GUILD`).
617    ///
618    /// discord.js counterpart: the `AutoModerationRuleUpdate` event.
619    AutoModerationRuleUpdate(Rule)
620}
621
622newtype_event! {
623    /// The data of the [Auto Moderation Rule Delete](https://docs.discord.com/developers/events/gateway-events#auto-moderation-rule-delete)
624    /// dispatch event (requires `MANAGE_GUILD`).
625    ///
626    /// discord.js counterpart: the `AutoModerationRuleDelete` event.
627    AutoModerationRuleDelete(Rule)
628}
629
630/// The data of the [Auto Moderation Action Execution](https://docs.discord.com/developers/events/gateway-events#auto-moderation-action-execution)
631/// dispatch event: a rule triggered and one of its actions ran (requires `MANAGE_GUILD`; the
632/// content fields require the `MESSAGE_CONTENT` intent).
633///
634/// discord.js counterpart: the `AutoModerationActionExecution` event.
635#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
636#[non_exhaustive]
637pub struct AutoModerationActionExecution {
638    /// The guild.
639    pub guild_id: GuildId,
640    /// The action that ran.
641    pub action: Action,
642    /// The rule.
643    pub rule_id: AutoModerationRuleId,
644    /// The rule's trigger type.
645    pub rule_trigger_type: TriggerType,
646    /// The user whose content triggered the rule.
647    pub user_id: UserId,
648    /// The channel the content was posted in.
649    #[serde(default, skip_serializing_if = "Option::is_none")]
650    pub channel_id: Option<ChannelId>,
651    /// The user's message (absent if it was blocked or the content was not a message).
652    #[serde(default, skip_serializing_if = "Option::is_none")]
653    pub message_id: Option<MessageId>,
654    /// The alert message posted by a `SEND_ALERT_MESSAGE` action.
655    #[serde(default, skip_serializing_if = "Option::is_none")]
656    pub alert_system_message_id: Option<MessageId>,
657    /// The user's content (empty without the `MESSAGE_CONTENT` intent).
658    #[serde(default)]
659    pub content: CompactString,
660    /// The keyword or phrase of the rule that matched.
661    #[serde(default)]
662    pub matched_keyword: Option<CompactString>,
663    /// The part of the content that matched (`None` without the `MESSAGE_CONTENT` intent).
664    #[serde(default)]
665    pub matched_content: Option<CompactString>,
666}
667
668newtype_event! {
669    /// The data of the [Application Command Permissions Update](https://docs.discord.com/developers/events/gateway-events#application-command-permissions-update)
670    /// dispatch event.
671    ///
672    /// discord.js counterpart: the `ApplicationCommandPermissionsUpdate` event.
673    ApplicationCommandPermissionsUpdate(GuildCommandPermissions)
674}