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
use bitflags::__impl_bitflags;
use serde::{
de::{Deserialize, Deserializer},
ser::{Serialize, Serializer},
};
/// [Gateway Intents] will limit the events your bot will receive via the gateway.
/// By default, no intents are specified by Serenity.
///
/// [Gateway Intents]: https://discordapp.com/developers/docs/topics/gateway#gateway-intents
#[derive(Copy, PartialEq, Eq, Clone, PartialOrd, Ord, Hash)]
pub struct GatewayIntents {
/// The flags composing gateway intents.
///
/// # Note
/// Do not modify this yourself; use the provided methods.
/// Do the same when creating, unless you're absolutely certain that you're giving valid intents flags.
pub bits: u64
}
__impl_bitflags! {
GatewayIntents: u64 {
/// Enables following gateway events:
///
/// - GUILD_CREATE
/// - GUILD_DELETE
/// - GUILD_ROLE_CREATE
/// - GUILD_ROLE_UPDATE
/// - GUILD_ROLE_DELETE
/// - CHANNEL_CREATE
/// - CHANNEL_UPDATE
/// - CHANNEL_DELETE
/// - CHANNEL_PINS_UPDATE
GUILDS = 1;
/// Enables following gateway events:
///
/// - GUILD_MEMBER_ADD
/// - GUILD_MEMBER_UPDATE
/// - GUILD_MEMBER_REMOVE
///
/// **Info**:
/// This intent is *privileged*.
/// In order to use it, you must head to your application in the
/// Developer Portal and enable the toggle for *Privileged Intents*.
///
/// This intent is also necessary to even recieve the events in contains.
GUILD_MEMBERS = 1 << 1;
/// Enables following gateway events:
///
/// - GUILD_BAN_ADD
/// - GUILD_BAN_REMOVE
GUILD_BANS = 1 << 2;
/// Enables following gateway event:
///
/// - GUILD_EMOJIS_UPDATE
GUILD_EMOJIS = 1 << 3;
/// Enables following gateway event:
///
/// - GUILD_INTEGRATIONS_UPDATE
GUILD_INTEGRATIONS = 1 << 4;
/// Enables following gateway event:
///
/// - WEBHOOKS_UPDATE
GUILD_WEBHOOKS = 1 << 5;
/// Enables following gateway events:
///
/// - INVITE_CREATE
/// - INVITE_DELETE
GUILD_INVITES = 1 << 6;
/// Enables following gateway event:
///
/// - VOICE_STATE_UPDATE
GUILD_VOICE_STATES = 1 << 7;
/// Enables following gateway event:
///
/// - PRESENCE_UPDATE
///
/// **Info**:
/// This intent is *privileged*.
/// In order to use it, you must head to your application in the
/// Developer Portal and enable the toggle for *Privileged Intents*.
///
/// This intent is also necessary to even recieve the events in contains.
GUILD_PRESENCES = 1 << 8;
/// Enables following gateway events:
///
/// - MESSAGE_CREATE
/// - MESSAGE_UPDATE
/// - MESSAGE_DELETE
GUILD_MESSAGES = 1 << 9;
/// Enables following gateway events:
///
/// - MESSAGE_REACTION_ADD
/// - MESSAGE_REACTION_REMOVE
/// - MESSAGE_REACTION_REMOVE_ALL
/// - MESSAGE_REACTION_REMOVE_EMOJI
GUILD_MESSAGE_REACTIONS = 1 << 10;
/// Enable following gateway event:
///
/// - TYPING_START
GUILD_MESSAGE_TYPING = 1 << 11;
/// Enable following gateway events:
///
/// - CHANNEL_CREATE
/// - MESSAGE_CREATE
/// - MESSAGE_UPDATE
/// - MESSAGE_DELETE
/// - CHANNEL_PINS_UPDATE
DIRECT_MESSAGES = 1 << 12;
/// Enable following gateway events:
///
/// - MESSAGE_REACTION_ADD
/// - MESSAGE_REACTION_REMOVE
/// - MESSAGE_REACTION_REMOVE_ALL
/// - MESSAGE_REACTION_REMOVE_EMOJI
DIRECT_MESSAGE_REACTIONS = 1 << 13;
/// Enable following gateway event:
///
/// - TYPING_START
DIRECT_MESSAGE_TYPING = 1 << 14;
}
}
impl Default for GatewayIntents {
fn default() -> Self { Self::empty() }
}
impl<'de> Deserialize<'de> for GatewayIntents {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Ok(Self::from_bits_truncate(u64::deserialize(deserializer)?))
}
}
impl Serialize for GatewayIntents {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_u64(self.bits())
}
}
#[cfg(feature = "model")]
impl GatewayIntents {
/// Shorthand for checking that the set of intents contains the
/// [GUILDS] intent.
///
/// [GUILDS]: #associatedconstant.GUILDS
pub fn guilds(self) -> bool {
self.contains(Self::GUILDS)
}
/// Shorthand for checking that the set of intents contains the
/// [GUILD_MEMBERS] intent.
///
/// [GUILD_MEMBERS]: #associatedconstant.GUILD_MEMBERS
pub fn guild_members(self) -> bool {
self.contains(Self::GUILD_MEMBERS)
}
/// Shorthand for checking that the set of intents contains the
/// [GUILD_BANS] intent.
///
/// [GUILD_BANS]: #associatedconstant.GUILD_BANS
pub fn guild_bans(self) -> bool {
self.contains(Self::GUILD_BANS)
}
/// Shorthand for checking that the set of intents contains the
/// [GUILD_EMOJIS] intent.
///
/// [GUILD_EMOJIS]: #associatedconstant.GUILD_EMOJIS
pub fn guild_emojis(self) -> bool {
self.contains(Self::GUILD_EMOJIS)
}
/// Shorthand for checking that the set of intents contains the
/// [GUILD_INTEGRATIONS] intent.
///
/// [GUILD_INTEGRATIONS]: #associatedconstant.GUILD_INTEGRATIONS
pub fn guild_integrations(self) -> bool {
self.contains(Self::GUILD_INTEGRATIONS)
}
/// Shorthand for checking that the set of intents contains the
/// [GUILD_WEBHOOKS] intent.
///
/// [GUILD_WEBHOOKS]: #associatedconstant.GUILD_WEBHOOKS
pub fn guild_webhooks(self) -> bool {
self.contains(Self::GUILD_WEBHOOKS)
}
/// Shorthand for checking that the set of intents contains the
/// [GUILD_INVITES] intent.
///
/// [GUILD_INVITES]: #associatedconstant.GUILD_INVITES
pub fn guild_invites(self) -> bool {
self.contains(Self::GUILD_INVITES)
}
/// Shorthand for checking that the set of intents contains the
/// [GUILD_VOICE_STATES] intent.
///
/// [GUILD_VOICE_STATES]: #associatedconstant.GUILD_VOICE_STATES
pub fn guild_voice_states(self) -> bool {
self.contains(Self::GUILD_VOICE_STATES)
}
/// Shorthand for checking that the set of intents contains the
/// [GUILD_PRESENCES] intent.
///
/// [GUILD_PRESENCES]: #associatedconstant.GUILD_PRESENCES
pub fn guild_presences(self) -> bool {
self.contains(Self::GUILD_PRESENCES)
}
/// Shorthand for checking that the set of intents contains the
/// [GUILD_MESSAGE_REACTIONS] intent.
///
/// [GUILD_MESSAGE_REACTIONS]: #associatedconstant.GUILD_MESSAGE_REACTIONS
pub fn guild_message_reactions(self) -> bool {
self.contains(Self::GUILD_MESSAGE_REACTIONS)
}
/// Shorthand for checking that the set of intents contains the
/// [GUILD_MESSAGE_TYPING] intent.
///
/// [GUILD_MESSAGE_TYPING]: #associatedconstant.GUILD_MESSAGE_TYPING
pub fn guild_message_typing(self) -> bool {
self.contains(Self::GUILD_MESSAGE_TYPING)
}
/// Shorthand for checking that the set of intents contains the
/// [DIRECT_MESSAGES] intent.
///
/// [DIRECT_MESSAGES]: #associatedconstant.DIRECT_MESSAGES
pub fn direct_messages(self) -> bool {
self.contains(Self::DIRECT_MESSAGES)
}
/// Shorthand for checking that the set of intents contains the
/// [DIRECT_MESSAGE_REACTIONS] intent.
///
/// [DIRECT_MESSAGE_REACTIONS]: #associatedconstant.DIRECT_MESSAGE_REACTIONS
pub fn direct_message_reactions(self) -> bool {
self.contains(Self::DIRECT_MESSAGE_REACTIONS)
}
/// Shorthand for checking that the set of intents contains the
/// [DIRECT_MESSAGE_TYPING] intent.
///
/// [DIRECT_MESSAGE_TYPING]: #associatedconstant.DIRECT_MESSAGE_TYPING
pub fn direct_message_typing(self) -> bool {
self.contains(Self::DIRECT_MESSAGE_TYPING)
}
}