djs_rest/route.rs
1//! Typed REST API routes.
2
3use core::fmt;
4
5use djs_model::{
6 emoji::{Emoji, PartialEmoji},
7 id::{
8 ApplicationId, AutoModerationRuleId, ChannelId, CommandId, EmojiId, EntitlementId,
9 GenericId, GuildId, Id, IntegrationId, InteractionId, LobbyId, MessageId, RoleId,
10 ScheduledEventId, SkuId, SoundboardSoundId, StickerId, StickerPackId, SubscriptionId,
11 UserId, WebhookId,
12 },
13 util::Timestamp,
14};
15use http::Method;
16
17/// How the requests of a route are rate limited.
18#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
19pub(crate) struct Limits {
20 /// Whether the route counts towards the bot's global rate limit.
21 pub(crate) global: bool,
22 /// Whether requests are sent at once instead of one after another per bucket
23 /// (interaction callbacks; like discord.js' `BurstHandler`). A 429 then only delays the
24 /// request that received it.
25 pub(crate) burst: bool,
26}
27
28impl Limits {
29 /// A normal route: one request at a time per bucket, counted globally.
30 pub(crate) const NORMAL: Self = Self {
31 global: true,
32 burst: false,
33 };
34 /// [Interaction endpoints](https://docs.discord.com/developers/topics/rate-limits#global-rate-limit)
35 /// are not bound to the global rate limit.
36 const INTERACTION: Self = Self {
37 global: false,
38 burst: false,
39 };
40 /// Interaction callbacks must be answered within 3 seconds, so they never wait for one
41 /// another.
42 const INTERACTION_CALLBACK: Self = Self {
43 global: false,
44 burst: true,
45 };
46}
47
48/// How a route is grouped for rate limiting.
49#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
50pub(crate) struct BucketRoute {
51 /// A unique, static description of the route *without* its parameters, e.g.
52 /// `"POST /channels/{channel_id}/messages"`. Routes sharing a template share a bucket hash.
53 pub(crate) template: &'static str,
54 /// The [major parameter](https://docs.discord.com/developers/topics/rate-limits) (channel,
55 /// guild or webhook ID, or webhook ID + token), or `0` if the route has none. Rate limits
56 /// are tracked separately per major parameter.
57 pub(crate) major: u64,
58 /// How the route is limited.
59 pub(crate) limits: Limits,
60}
61
62/// Messages older than this are deleted under a separate, stricter rate limit.
63const OLD_MESSAGE_AGE_MS: u64 = 14 * 24 * 60 * 60 * 1000;
64
65/// The bucket template of [`Route::DeleteMessage`] for messages older than two weeks.
66const OLD_MESSAGE_DELETE: &str =
67 "DELETE /channels/{channel_id}/messages/{message_id} (older than two weeks)";
68
69/// The emoji of a reaction endpoint (D-103), written into the path percent-encoded.
70///
71/// Discord identifies a Unicode emoji by the emoji itself and a custom emoji by `name:id`;
72/// this type writes the right form, so a wrong format is impossible.
73///
74/// discord.js counterpart: `EmojiIdentifierResolvable`.
75///
76/// # Examples
77///
78/// ```
79/// use djs_model::id::{ChannelId, EmojiId, MessageId};
80/// use djs_rest::{ReactionEmoji, Route};
81///
82/// let route = |emoji| Route::CreateReaction {
83/// channel_id: ChannelId::new(1),
84/// message_id: MessageId::new(2),
85/// emoji,
86/// };
87/// assert_eq!(
88/// route(ReactionEmoji::Unicode("👍")).path(),
89/// "/channels/1/messages/2/reactions/%F0%9F%91%8D/@me"
90/// );
91/// assert_eq!(
92/// route(ReactionEmoji::Custom { name: "ferris", id: EmojiId::new(3) }).path(),
93/// "/channels/1/messages/2/reactions/ferris%3A3/@me"
94/// );
95/// // A `&str` is a Unicode emoji.
96/// assert_eq!(ReactionEmoji::from("🔥"), ReactionEmoji::Unicode("🔥"));
97/// ```
98#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
99pub enum ReactionEmoji<'a> {
100 /// A standard Unicode emoji such as `👍`.
101 Unicode(&'a str),
102 /// A custom (guild or application) emoji.
103 Custom {
104 /// The emoji's name.
105 name: &'a str,
106 /// The emoji's ID.
107 id: EmojiId,
108 },
109}
110
111impl<'a> From<&'a str> for ReactionEmoji<'a> {
112 /// A Unicode emoji.
113 fn from(emoji: &'a str) -> Self {
114 Self::Unicode(emoji)
115 }
116}
117
118impl<'a> From<&'a Emoji> for ReactionEmoji<'a> {
119 fn from(emoji: &'a Emoji) -> Self {
120 Self::Custom {
121 name: &emoji.name,
122 id: emoji.id,
123 }
124 }
125}
126
127impl<'a> From<&'a PartialEmoji> for ReactionEmoji<'a> {
128 /// A custom emoji whose name Discord no longer knows gets the name `_` (only the ID
129 /// identifies it).
130 fn from(emoji: &'a PartialEmoji) -> Self {
131 match emoji {
132 PartialEmoji::Custom { id, name, .. } => Self::Custom {
133 name: name.as_deref().unwrap_or("_"),
134 id: *id,
135 },
136 PartialEmoji::Unicode { name } => Self::Unicode(name),
137 }
138 }
139}
140
141/// A path parameter of a route.
142#[derive(Clone, Copy)]
143enum Segment<'a> {
144 Id(u64),
145 Text(&'a str),
146 Emoji(ReactionEmoji<'a>),
147}
148
149/// A value that can appear in a route's path.
150trait Param: Copy {
151 /// The value as a path segment.
152 fn to_segment<'a>(self) -> Segment<'a>
153 where
154 Self: 'a;
155
156 /// The value's contribution to the major parameter.
157 fn major(self) -> u64;
158
159 /// Writes the value for `Debug`, redacting tokens.
160 fn debug(self, name: &str, out: &mut fmt::DebugStruct<'_, '_>);
161}
162
163impl<M> Param for Id<M> {
164 fn to_segment<'a>(self) -> Segment<'a>
165 where
166 Self: 'a,
167 {
168 Segment::Id(self.get())
169 }
170
171 fn major(self) -> u64 {
172 self.get()
173 }
174
175 fn debug(self, name: &str, out: &mut fmt::DebugStruct<'_, '_>) {
176 out.field(name, &self.get());
177 }
178}
179
180/// Small numeric IDs that are not snowflakes (a poll's `answer_id`).
181impl Param for u32 {
182 fn to_segment<'a>(self) -> Segment<'a>
183 where
184 Self: 'a,
185 {
186 Segment::Id(u64::from(self))
187 }
188
189 fn major(self) -> u64 {
190 u64::from(self)
191 }
192
193 fn debug(self, name: &str, out: &mut fmt::DebugStruct<'_, '_>) {
194 out.field(name, &self);
195 }
196}
197
198impl Param for &str {
199 fn to_segment<'a>(self) -> Segment<'a>
200 where
201 Self: 'a,
202 {
203 Segment::Text(self)
204 }
205
206 fn major(self) -> u64 {
207 // FNV-1a: a stable, cheap hash, so that every token gets its own bucket.
208 self.bytes().fold(0xcbf2_9ce4_8422_2325, |hash, byte| {
209 (hash ^ u64::from(byte)).wrapping_mul(0x0100_0000_01b3)
210 })
211 }
212
213 fn debug(self, name: &str, out: &mut fmt::DebugStruct<'_, '_>) {
214 if name.ends_with("token") {
215 out.field(name, &"<redacted>");
216 } else {
217 out.field(name, &self);
218 }
219 }
220}
221
222impl Param for ReactionEmoji<'_> {
223 fn to_segment<'a>(self) -> Segment<'a>
224 where
225 Self: 'a,
226 {
227 Segment::Emoji(self)
228 }
229
230 fn major(self) -> u64 {
231 // Never a major parameter: all emojis of a message share the reaction buckets.
232 0
233 }
234
235 fn debug(self, name: &str, out: &mut fmt::DebugStruct<'_, '_>) {
236 out.field(name, &self);
237 }
238}
239
240/// Combines major parameter parts (webhook ID + token).
241const fn combine(hash: u64, part: u64) -> u64 {
242 (hash.rotate_left(29) ^ part).wrapping_mul(0x9e37_79b9_7f4a_7c15)
243}
244
245/// Writes `text` as one path segment, percent-encoding everything but unreserved characters
246/// (RFC 3986), so a parameter can never change the structure of the path.
247pub(crate) fn write_text(out: &mut String, text: &str) {
248 const HEX: &[u8; 16] = b"0123456789ABCDEF";
249 for byte in text.bytes() {
250 if byte.is_ascii_alphanumeric() || matches!(byte, b'-' | b'.' | b'_' | b'~') {
251 out.push(char::from(byte));
252 } else {
253 out.push('%');
254 out.push(char::from(HEX[usize::from(byte >> 4)]));
255 out.push(char::from(HEX[usize::from(byte & 0xf)]));
256 }
257 }
258}
259
260/// Writes `template` with every `{name}` replaced by the matching parameter.
261fn write_template(out: &mut String, template: &str, params: &[(&str, Segment<'_>)]) {
262 let mut rest = template;
263 while let Some(open) = rest.find('{') {
264 out.push_str(&rest[..open]);
265 let after = &rest[open + 1..];
266 let close = after.find('}').unwrap_or(after.len());
267 let name = &after[..close];
268 match params.iter().find(|(param, _)| *param == name) {
269 Some((_, Segment::Id(id))) => {
270 // Writing to a `String` cannot fail.
271 let _ = fmt::Write::write_fmt(out, format_args!("{id}"));
272 }
273 Some((_, Segment::Text(text))) => write_text(out, text),
274 Some((_, Segment::Emoji(ReactionEmoji::Unicode(emoji)))) => write_text(out, emoji),
275 Some((_, Segment::Emoji(ReactionEmoji::Custom { name, id }))) => {
276 write_text(out, name);
277 let _ = fmt::Write::write_fmt(out, format_args!("%3A{id}"));
278 }
279 None => debug_assert!(false, "unknown route parameter {{{name}}} in {template}"),
280 }
281 rest = after.get(close + 1..).unwrap_or("");
282 }
283 out.push_str(rest);
284}
285
286macro_rules! routes {
287 ($(
288 $(#[doc = $doc:literal])*
289 $variant:ident $({ $( $(#[doc = $field_doc:literal])* $field:ident: $ty:ty ),* $(,)? })?
290 => $method:ident $template:literal
291 $(, major: $($major:ident)+)?
292 $(, limits: $limits:ident)?;
293 )*) => {
294 /// A Discord REST API endpoint together with its path parameters.
295 ///
296 /// Each route knows its HTTP method, its path and how it is
297 /// [rate limited](https://docs.discord.com/developers/topics/rate-limits). Most code uses
298 /// the typed methods on [`Rest`](crate::Rest) instead of building routes directly;
299 /// routes are useful with the low-level [`Rest::request`](crate::Rest::request).
300 ///
301 /// Tokens (interaction and webhook tokens) are borrowed (D-090), percent-encoded in the
302 /// path and redacted in the `Debug` output.
303 ///
304 /// discord.js counterpart: the `Routes` helper of discord-api-types.
305 ///
306 /// # Examples
307 ///
308 /// ```
309 /// use djs_model::id::ChannelId;
310 /// use djs_rest::Route;
311 ///
312 /// let route = Route::CreateMessage { channel_id: ChannelId::new(42) };
313 /// assert_eq!(route.method(), http::Method::POST);
314 /// assert_eq!(route.path(), "/channels/42/messages");
315 /// ```
316 #[derive(Clone, Copy, PartialEq, Eq, Hash)]
317 #[non_exhaustive]
318 pub enum Route<'a> {
319 $(
320 $(#[doc = $doc])*
321 #[doc = ""]
322 #[doc = concat!("`", stringify!($method), " ", $template, "`")]
323 $variant $({ $( $(#[doc = $field_doc])* $field: $ty ),* })?,
324 )*
325 }
326
327 impl Route<'_> {
328 /// Returns the HTTP method of the route.
329 ///
330 /// discord.js counterpart: the method `REST#request` is given (`@discordjs/rest`).
331 #[must_use]
332 pub fn method(self) -> Method {
333 match self {
334 $(Self::$variant { .. } => Method::$method,)*
335 }
336 }
337
338 /// Returns the path of the route, relative to the versioned API base
339 /// (e.g. `/channels/42/messages`).
340 ///
341 /// discord.js counterpart: the `fullRoute` `REST#request` is given (`@discordjs/rest`).
342 #[must_use]
343 pub fn path(self) -> String {
344 let mut path = String::with_capacity(64);
345 self.write_path(&mut path);
346 path
347 }
348
349 /// Appends the path of the route to `out`.
350 pub(crate) fn write_path(self, out: &mut String) {
351 match self {
352 $(Self::$variant $({ $($field),* })? => write_template(
353 out,
354 $template,
355 &[$($( (stringify!($field), Param::to_segment($field)) ),*)?],
356 ),)*
357 }
358 }
359
360 /// Whether the route has a `*_token` path parameter (a webhook or interaction
361 /// token), which authenticates it instead of the client's token (D-121).
362 fn has_token_parameter(self) -> bool {
363 match self {
364 $(Self::$variant { .. } => [$($(stringify!($field)),*)?]
365 .iter()
366 .any(|name: &&str| name.ends_with("token")),)*
367 }
368 }
369
370 /// Returns the rate-limit grouping of the route, before route-specific exceptions.
371 fn base_bucket(self) -> BucketRoute {
372 match self {
373 $(
374 #[allow(unused_variables, reason = "not every route has a major parameter")]
375 Self::$variant $({ $($field),* })? => BucketRoute {
376 template: concat!(stringify!($method), " ", $template),
377 major: 0 $($( ^ combine(0, Param::major($major)) )+)?,
378 limits: routes!(@limits $($limits)?),
379 },
380 )*
381 }
382 }
383 }
384
385 impl fmt::Debug for Route<'_> {
386 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
387 match *self {
388 $(
389 #[allow(unused_mut, reason = "unit routes have no fields")]
390 Self::$variant $({ $($field),* })? => {
391 let mut out = f.debug_struct(stringify!($variant));
392 $($( Param::debug($field, stringify!($field), &mut out); )*)?
393 out.finish()
394 }
395 )*
396 }
397 }
398 }
399 };
400 (@limits) => { Limits::NORMAL };
401 (@limits $limits:ident) => { Limits::$limits };
402}
403
404impl Route<'_> {
405 /// Whether the request carries the client's token. Routes authenticated by a webhook or
406 /// interaction token in their path are sent without it (D-121), and so are the `OAuth2`
407 /// token endpoints, which take the application's client credentials in their body
408 /// (D-132).
409 pub(crate) fn authenticated(self) -> bool {
410 !self.has_token_parameter()
411 && !matches!(
412 self,
413 Self::OAuth2TokenExchange | Self::OAuth2TokenRevocation
414 )
415 }
416
417 /// Returns the rate-limit grouping of the route.
418 pub(crate) fn bucket(self) -> BucketRoute {
419 // djs-model's clock, which also works on wasm32 (D-397).
420 let now_ms = u64::try_from(Timestamp::now().as_unix_millis()).unwrap_or(0);
421 self.bucket_at(now_ms)
422 }
423
424 /// [`bucket`](Self::bucket) at the Unix time `now_ms` (milliseconds).
425 fn bucket_at(self, now_ms: u64) -> BucketRoute {
426 let mut bucket = self.base_bucket();
427 // Deleting a message older than two weeks is limited separately from newer ones
428 // (https://github.com/discord/discord-api-docs/issues/1295; discord.js does the same).
429 if let Self::DeleteMessage { message_id, .. } = self
430 && now_ms.saturating_sub(message_id.timestamp_ms()) > OLD_MESSAGE_AGE_MS
431 {
432 bucket.template = OLD_MESSAGE_DELETE;
433 }
434 bucket
435 }
436}
437
438routes! {
439 /// [Get Gateway](https://docs.discord.com/developers/events/gateway#get-gateway).
440 GetGateway => GET "/gateway";
441 /// [Get Gateway Bot](https://docs.discord.com/developers/events/gateway#get-gateway-bot).
442 GetGatewayBot => GET "/gateway/bot";
443
444 // Guilds.
445
446 /// [Get Guild](https://docs.discord.com/developers/resources/guild#get-guild).
447 GetGuild {
448 /// The guild.
449 guild_id: GuildId,
450 } => GET "/guilds/{guild_id}", major: guild_id;
451
452 /// [Get Guild Preview](https://docs.discord.com/developers/resources/guild#get-guild-preview).
453 GetGuildPreview {
454 /// The guild.
455 guild_id: GuildId,
456 } => GET "/guilds/{guild_id}/preview", major: guild_id;
457
458 /// [Modify Guild](https://docs.discord.com/developers/resources/guild#modify-guild).
459 ModifyGuild {
460 /// The guild.
461 guild_id: GuildId,
462 } => PATCH "/guilds/{guild_id}", major: guild_id;
463
464 /// [Get Guild Channels](https://docs.discord.com/developers/resources/guild#get-guild-channels).
465 GetGuildChannels {
466 /// The guild.
467 guild_id: GuildId,
468 } => GET "/guilds/{guild_id}/channels", major: guild_id;
469
470 /// [Create Guild Channel](https://docs.discord.com/developers/resources/guild#create-guild-channel).
471 CreateGuildChannel {
472 /// The guild.
473 guild_id: GuildId,
474 } => POST "/guilds/{guild_id}/channels", major: guild_id;
475
476 /// [Modify Guild Channel Positions](https://docs.discord.com/developers/resources/guild#modify-guild-channel-positions).
477 ModifyGuildChannelPositions {
478 /// The guild.
479 guild_id: GuildId,
480 } => PATCH "/guilds/{guild_id}/channels", major: guild_id;
481
482 /// [List Active Guild Threads](https://docs.discord.com/developers/resources/guild#list-active-guild-threads).
483 ListActiveGuildThreads {
484 /// The guild.
485 guild_id: GuildId,
486 } => GET "/guilds/{guild_id}/threads/active", major: guild_id;
487
488 /// [Get Guild Member](https://docs.discord.com/developers/resources/guild#get-guild-member).
489 GetGuildMember {
490 /// The guild.
491 guild_id: GuildId,
492 /// The user.
493 user_id: UserId,
494 } => GET "/guilds/{guild_id}/members/{user_id}", major: guild_id;
495
496 /// [List Guild Members](https://docs.discord.com/developers/resources/guild#list-guild-members).
497 ListGuildMembers {
498 /// The guild.
499 guild_id: GuildId,
500 } => GET "/guilds/{guild_id}/members", major: guild_id;
501
502 /// [Search Guild Members](https://docs.discord.com/developers/resources/guild#search-guild-members).
503 SearchGuildMembers {
504 /// The guild.
505 guild_id: GuildId,
506 } => GET "/guilds/{guild_id}/members/search", major: guild_id;
507
508 /// [Get Guild Member Permissions](https://docs.discord.com/developers/resources/guild#get-guild-member-permissions).
509 GetGuildMemberPermissions {
510 /// The guild.
511 guild_id: GuildId,
512 /// The user.
513 user_id: UserId,
514 } => GET "/guilds/{guild_id}/permissions/member/{user_id}", major: guild_id;
515
516 /// [Add Guild Member](https://docs.discord.com/developers/resources/guild#add-guild-member).
517 AddGuildMember {
518 /// The guild.
519 guild_id: GuildId,
520 /// The user.
521 user_id: UserId,
522 } => PUT "/guilds/{guild_id}/members/{user_id}", major: guild_id;
523
524 /// [Modify Guild Member](https://docs.discord.com/developers/resources/guild#modify-guild-member).
525 ModifyGuildMember {
526 /// The guild.
527 guild_id: GuildId,
528 /// The user.
529 user_id: UserId,
530 } => PATCH "/guilds/{guild_id}/members/{user_id}", major: guild_id;
531
532 /// [Modify Current Member](https://docs.discord.com/developers/resources/guild#modify-current-member).
533 ModifyCurrentMember {
534 /// The guild.
535 guild_id: GuildId,
536 } => PATCH "/guilds/{guild_id}/members/@me", major: guild_id;
537
538 /// [Add Guild Member Role](https://docs.discord.com/developers/resources/guild#add-guild-member-role).
539 AddGuildMemberRole {
540 /// The guild.
541 guild_id: GuildId,
542 /// The user.
543 user_id: UserId,
544 /// The role.
545 role_id: RoleId,
546 } => PUT "/guilds/{guild_id}/members/{user_id}/roles/{role_id}", major: guild_id;
547
548 /// [Remove Guild Member Role](https://docs.discord.com/developers/resources/guild#remove-guild-member-role).
549 RemoveGuildMemberRole {
550 /// The guild.
551 guild_id: GuildId,
552 /// The user.
553 user_id: UserId,
554 /// The role.
555 role_id: RoleId,
556 } => DELETE "/guilds/{guild_id}/members/{user_id}/roles/{role_id}", major: guild_id;
557
558 /// [Remove Guild Member](https://docs.discord.com/developers/resources/guild#remove-guild-member).
559 RemoveGuildMember {
560 /// The guild.
561 guild_id: GuildId,
562 /// The user.
563 user_id: UserId,
564 } => DELETE "/guilds/{guild_id}/members/{user_id}", major: guild_id;
565
566 /// [Get Guild Bans](https://docs.discord.com/developers/resources/guild#get-guild-bans).
567 GetGuildBans {
568 /// The guild.
569 guild_id: GuildId,
570 } => GET "/guilds/{guild_id}/bans", major: guild_id;
571
572 /// [Get Guild Ban](https://docs.discord.com/developers/resources/guild#get-guild-ban).
573 GetGuildBan {
574 /// The guild.
575 guild_id: GuildId,
576 /// The user.
577 user_id: UserId,
578 } => GET "/guilds/{guild_id}/bans/{user_id}", major: guild_id;
579
580 /// [Create Guild Ban](https://docs.discord.com/developers/resources/guild#create-guild-ban).
581 CreateGuildBan {
582 /// The guild.
583 guild_id: GuildId,
584 /// The user.
585 user_id: UserId,
586 } => PUT "/guilds/{guild_id}/bans/{user_id}", major: guild_id;
587
588 /// [Remove Guild Ban](https://docs.discord.com/developers/resources/guild#remove-guild-ban).
589 RemoveGuildBan {
590 /// The guild.
591 guild_id: GuildId,
592 /// The user.
593 user_id: UserId,
594 } => DELETE "/guilds/{guild_id}/bans/{user_id}", major: guild_id;
595
596 /// [Bulk Guild Ban](https://docs.discord.com/developers/resources/guild#bulk-guild-ban).
597 BulkGuildBan {
598 /// The guild.
599 guild_id: GuildId,
600 } => POST "/guilds/{guild_id}/bulk-ban", major: guild_id;
601
602 /// [Get Guild Roles](https://docs.discord.com/developers/resources/guild#get-guild-roles).
603 GetGuildRoles {
604 /// The guild.
605 guild_id: GuildId,
606 } => GET "/guilds/{guild_id}/roles", major: guild_id;
607
608 /// [Get Guild Role](https://docs.discord.com/developers/resources/guild#get-guild-role).
609 GetGuildRole {
610 /// The guild.
611 guild_id: GuildId,
612 /// The role.
613 role_id: RoleId,
614 } => GET "/guilds/{guild_id}/roles/{role_id}", major: guild_id;
615
616 /// [Get Guild Role Permissions](https://docs.discord.com/developers/resources/guild#get-guild-role-permissions).
617 GetGuildRolePermissions {
618 /// The guild.
619 guild_id: GuildId,
620 /// The role.
621 role_id: RoleId,
622 } => GET "/guilds/{guild_id}/permissions/role/{role_id}", major: guild_id;
623
624 /// [Get Guild Role Member Counts](https://docs.discord.com/developers/resources/guild#get-guild-role-member-counts).
625 GetGuildRoleMemberCounts {
626 /// The guild.
627 guild_id: GuildId,
628 } => GET "/guilds/{guild_id}/roles/member-counts", major: guild_id;
629
630 /// [Create Guild Role](https://docs.discord.com/developers/resources/guild#create-guild-role).
631 CreateGuildRole {
632 /// The guild.
633 guild_id: GuildId,
634 } => POST "/guilds/{guild_id}/roles", major: guild_id;
635
636 /// [Modify Guild Role Positions](https://docs.discord.com/developers/resources/guild#modify-guild-role-positions).
637 ModifyGuildRolePositions {
638 /// The guild.
639 guild_id: GuildId,
640 } => PATCH "/guilds/{guild_id}/roles", major: guild_id;
641
642 /// [Modify Guild Role](https://docs.discord.com/developers/resources/guild#modify-guild-role).
643 ModifyGuildRole {
644 /// The guild.
645 guild_id: GuildId,
646 /// The role.
647 role_id: RoleId,
648 } => PATCH "/guilds/{guild_id}/roles/{role_id}", major: guild_id;
649
650 /// [Delete Guild Role](https://docs.discord.com/developers/resources/guild#delete-guild-role).
651 DeleteGuildRole {
652 /// The guild.
653 guild_id: GuildId,
654 /// The role.
655 role_id: RoleId,
656 } => DELETE "/guilds/{guild_id}/roles/{role_id}", major: guild_id;
657
658 /// [Get Guild Prune Count](https://docs.discord.com/developers/resources/guild#get-guild-prune-count).
659 GetGuildPruneCount {
660 /// The guild.
661 guild_id: GuildId,
662 } => GET "/guilds/{guild_id}/prune", major: guild_id;
663
664 /// [Begin Guild Prune](https://docs.discord.com/developers/resources/guild#begin-guild-prune).
665 BeginGuildPrune {
666 /// The guild.
667 guild_id: GuildId,
668 } => POST "/guilds/{guild_id}/prune", major: guild_id;
669
670 /// [Get Guild Voice Regions](https://docs.discord.com/developers/resources/guild#get-guild-voice-regions).
671 GetGuildVoiceRegions {
672 /// The guild.
673 guild_id: GuildId,
674 } => GET "/guilds/{guild_id}/regions", major: guild_id;
675
676 /// [Get Guild Invites](https://docs.discord.com/developers/resources/guild#get-guild-invites).
677 GetGuildInvites {
678 /// The guild.
679 guild_id: GuildId,
680 } => GET "/guilds/{guild_id}/invites", major: guild_id;
681
682 /// [Get Guild Integrations](https://docs.discord.com/developers/resources/guild#get-guild-integrations).
683 GetGuildIntegrations {
684 /// The guild.
685 guild_id: GuildId,
686 } => GET "/guilds/{guild_id}/integrations", major: guild_id;
687
688 /// [Delete Guild Integration](https://docs.discord.com/developers/resources/guild#delete-guild-integration).
689 DeleteGuildIntegration {
690 /// The guild.
691 guild_id: GuildId,
692 /// The integration.
693 integration_id: IntegrationId,
694 } => DELETE "/guilds/{guild_id}/integrations/{integration_id}", major: guild_id;
695
696 /// [Get Guild Widget Settings](https://docs.discord.com/developers/resources/guild#get-guild-widget-settings).
697 GetGuildWidgetSettings {
698 /// The guild.
699 guild_id: GuildId,
700 } => GET "/guilds/{guild_id}/widget", major: guild_id;
701
702 /// [Modify Guild Widget](https://docs.discord.com/developers/resources/guild#modify-guild-widget).
703 ModifyGuildWidget {
704 /// The guild.
705 guild_id: GuildId,
706 } => PATCH "/guilds/{guild_id}/widget", major: guild_id;
707
708 /// [Get Guild Widget](https://docs.discord.com/developers/resources/guild#get-guild-widget).
709 GetGuildWidget {
710 /// The guild.
711 guild_id: GuildId,
712 } => GET "/guilds/{guild_id}/widget.json", major: guild_id;
713
714 /// [Get Guild Vanity URL](https://docs.discord.com/developers/resources/guild#get-guild-vanity-url).
715 GetGuildVanityUrl {
716 /// The guild.
717 guild_id: GuildId,
718 } => GET "/guilds/{guild_id}/vanity-url", major: guild_id;
719
720 /// [Get Guild Welcome Screen](https://docs.discord.com/developers/resources/guild#get-guild-welcome-screen).
721 GetGuildWelcomeScreen {
722 /// The guild.
723 guild_id: GuildId,
724 } => GET "/guilds/{guild_id}/welcome-screen", major: guild_id;
725
726 /// [Modify Guild Welcome Screen](https://docs.discord.com/developers/resources/guild#modify-guild-welcome-screen).
727 ModifyGuildWelcomeScreen {
728 /// The guild.
729 guild_id: GuildId,
730 } => PATCH "/guilds/{guild_id}/welcome-screen", major: guild_id;
731
732 /// [Get Guild Onboarding](https://docs.discord.com/developers/resources/guild#get-guild-onboarding).
733 GetGuildOnboarding {
734 /// The guild.
735 guild_id: GuildId,
736 } => GET "/guilds/{guild_id}/onboarding", major: guild_id;
737
738 /// [Modify Guild Onboarding](https://docs.discord.com/developers/resources/guild#modify-guild-onboarding).
739 ModifyGuildOnboarding {
740 /// The guild.
741 guild_id: GuildId,
742 } => PUT "/guilds/{guild_id}/onboarding", major: guild_id;
743
744 /// [Modify Guild Incident Actions](https://docs.discord.com/developers/resources/guild#modify-guild-incident-actions).
745 ModifyGuildIncidentActions {
746 /// The guild.
747 guild_id: GuildId,
748 } => PUT "/guilds/{guild_id}/incident-actions", major: guild_id;
749
750 // Users. A guild ID inside a `/users/@me` path is not a major parameter (C-046).
751
752 /// [Get Current User](https://docs.discord.com/developers/resources/user#get-current-user).
753 GetCurrentUser => GET "/users/@me";
754
755 /// [Get User](https://docs.discord.com/developers/resources/user#get-user).
756 GetUser {
757 /// The user.
758 user_id: UserId,
759 } => GET "/users/{user_id}";
760
761 /// [Modify Current User](https://docs.discord.com/developers/resources/user#modify-current-user).
762 ModifyCurrentUser => PATCH "/users/@me";
763
764 /// [Get Current User Guilds](https://docs.discord.com/developers/resources/user#get-current-user-guilds).
765 GetCurrentUserGuilds => GET "/users/@me/guilds";
766
767 /// [Get Current User Guild Member](https://docs.discord.com/developers/resources/user#get-current-user-guild-member).
768 GetCurrentUserGuildMember {
769 /// The guild.
770 guild_id: GuildId,
771 } => GET "/users/@me/guilds/{guild_id}/member";
772
773 /// [Leave Guild](https://docs.discord.com/developers/resources/user#leave-guild).
774 LeaveGuild {
775 /// The guild.
776 guild_id: GuildId,
777 } => DELETE "/users/@me/guilds/{guild_id}";
778
779 /// [Create DM](https://docs.discord.com/developers/resources/user#create-dm).
780 CreateDm => POST "/users/@me/channels";
781
782 /// [Create Group DM](https://docs.discord.com/developers/resources/user#create-group-dm):
783 /// the same endpoint as [`CreateDm`](Self::CreateDm), with access tokens.
784 CreateGroupDm => POST "/users/@me/channels";
785
786 /// [Get Current User Connections](https://docs.discord.com/developers/resources/user#get-current-user-connections).
787 GetCurrentUserConnections => GET "/users/@me/connections";
788
789 /// [Get Current User Application Role Connection](https://docs.discord.com/developers/resources/user#get-current-user-application-role-connection).
790 GetCurrentUserApplicationRoleConnection {
791 /// The application.
792 application_id: ApplicationId,
793 } => GET "/users/@me/applications/{application_id}/role-connection";
794
795 /// [Update Current User Application Role Connection](https://docs.discord.com/developers/resources/user#update-current-user-application-role-connection).
796 UpdateCurrentUserApplicationRoleConnection {
797 /// The application.
798 application_id: ApplicationId,
799 } => PUT "/users/@me/applications/{application_id}/role-connection";
800
801 /// [Delete Current User Application Role Connection](https://docs.discord.com/developers/resources/user#delete-current-user-application-role-connection).
802 DeleteCurrentUserApplicationRoleConnection {
803 /// The application.
804 application_id: ApplicationId,
805 } => DELETE "/users/@me/applications/{application_id}/role-connection";
806
807 // Webhooks. Slack- and GitHub-compatible execution is not modelled (D-120).
808
809 /// [Create Webhook](https://docs.discord.com/developers/resources/webhook#create-webhook).
810 CreateWebhook {
811 /// The channel.
812 channel_id: ChannelId,
813 } => POST "/channels/{channel_id}/webhooks",
814 major: channel_id;
815
816 /// [Get Channel Webhooks](https://docs.discord.com/developers/resources/webhook#get-channel-webhooks).
817 GetChannelWebhooks {
818 /// The channel.
819 channel_id: ChannelId,
820 } => GET "/channels/{channel_id}/webhooks",
821 major: channel_id;
822
823 /// [Get Guild Webhooks](https://docs.discord.com/developers/resources/webhook#get-guild-webhooks).
824 GetGuildWebhooks {
825 /// The guild.
826 guild_id: GuildId,
827 } => GET "/guilds/{guild_id}/webhooks",
828 major: guild_id;
829
830 /// [Get Webhook](https://docs.discord.com/developers/resources/webhook#get-webhook).
831 GetWebhook {
832 /// The webhook.
833 webhook_id: WebhookId,
834 } => GET "/webhooks/{webhook_id}",
835 major: webhook_id;
836
837 /// [Get Webhook with Token](https://docs.discord.com/developers/resources/webhook#get-webhook-with-token).
838 GetWebhookWithToken {
839 /// The webhook.
840 webhook_id: WebhookId,
841 /// The webhook's token.
842 webhook_token: &'a str,
843 } => GET "/webhooks/{webhook_id}/{webhook_token}",
844 major: webhook_id webhook_token;
845
846 /// [Modify Webhook](https://docs.discord.com/developers/resources/webhook#modify-webhook).
847 ModifyWebhook {
848 /// The webhook.
849 webhook_id: WebhookId,
850 } => PATCH "/webhooks/{webhook_id}",
851 major: webhook_id;
852
853 /// [Modify Webhook with Token](https://docs.discord.com/developers/resources/webhook#modify-webhook-with-token).
854 ModifyWebhookWithToken {
855 /// The webhook.
856 webhook_id: WebhookId,
857 /// The webhook's token.
858 webhook_token: &'a str,
859 } => PATCH "/webhooks/{webhook_id}/{webhook_token}",
860 major: webhook_id webhook_token;
861
862 /// [Delete Webhook](https://docs.discord.com/developers/resources/webhook#delete-webhook).
863 DeleteWebhook {
864 /// The webhook.
865 webhook_id: WebhookId,
866 } => DELETE "/webhooks/{webhook_id}",
867 major: webhook_id;
868
869 /// [Delete Webhook with Token](https://docs.discord.com/developers/resources/webhook#delete-webhook-with-token).
870 DeleteWebhookWithToken {
871 /// The webhook.
872 webhook_id: WebhookId,
873 /// The webhook's token.
874 webhook_token: &'a str,
875 } => DELETE "/webhooks/{webhook_id}/{webhook_token}",
876 major: webhook_id webhook_token;
877
878 /// [Execute Webhook](https://docs.discord.com/developers/resources/webhook#execute-webhook).
879 ExecuteWebhook {
880 /// The webhook.
881 webhook_id: WebhookId,
882 /// The webhook's token.
883 webhook_token: &'a str,
884 } => POST "/webhooks/{webhook_id}/{webhook_token}",
885 major: webhook_id webhook_token;
886
887 /// [Get Webhook Message](https://docs.discord.com/developers/resources/webhook#get-webhook-message).
888 GetWebhookMessage {
889 /// The webhook.
890 webhook_id: WebhookId,
891 /// The webhook's token.
892 webhook_token: &'a str,
893 /// The message.
894 message_id: MessageId,
895 } => GET "/webhooks/{webhook_id}/{webhook_token}/messages/{message_id}",
896 major: webhook_id webhook_token;
897
898 /// [Edit Webhook Message](https://docs.discord.com/developers/resources/webhook#edit-webhook-message).
899 EditWebhookMessage {
900 /// The webhook.
901 webhook_id: WebhookId,
902 /// The webhook's token.
903 webhook_token: &'a str,
904 /// The message.
905 message_id: MessageId,
906 } => PATCH "/webhooks/{webhook_id}/{webhook_token}/messages/{message_id}",
907 major: webhook_id webhook_token;
908
909 /// [Delete Webhook Message](https://docs.discord.com/developers/resources/webhook#delete-webhook-message).
910 DeleteWebhookMessage {
911 /// The webhook.
912 webhook_id: WebhookId,
913 /// The webhook's token.
914 webhook_token: &'a str,
915 /// The message.
916 message_id: MessageId,
917 } => DELETE "/webhooks/{webhook_id}/{webhook_token}/messages/{message_id}",
918 major: webhook_id webhook_token;
919
920 // Emojis. Discord limits the guild emoji routes per guild, which the guild ID as the
921 // major parameter models.
922
923 /// [List Guild Emojis](https://docs.discord.com/developers/resources/emoji#list-guild-emojis).
924 ListGuildEmojis {
925 /// The guild.
926 guild_id: GuildId,
927 } => GET "/guilds/{guild_id}/emojis", major: guild_id;
928
929 /// [Get Guild Emoji](https://docs.discord.com/developers/resources/emoji#get-guild-emoji).
930 GetGuildEmoji {
931 /// The guild.
932 guild_id: GuildId,
933 /// The emoji.
934 emoji_id: EmojiId,
935 } => GET "/guilds/{guild_id}/emojis/{emoji_id}", major: guild_id;
936
937 /// [Create Guild Emoji](https://docs.discord.com/developers/resources/emoji#create-guild-emoji).
938 CreateGuildEmoji {
939 /// The guild.
940 guild_id: GuildId,
941 } => POST "/guilds/{guild_id}/emojis", major: guild_id;
942
943 /// [Modify Guild Emoji](https://docs.discord.com/developers/resources/emoji#modify-guild-emoji).
944 ModifyGuildEmoji {
945 /// The guild.
946 guild_id: GuildId,
947 /// The emoji.
948 emoji_id: EmojiId,
949 } => PATCH "/guilds/{guild_id}/emojis/{emoji_id}", major: guild_id;
950
951 /// [Delete Guild Emoji](https://docs.discord.com/developers/resources/emoji#delete-guild-emoji).
952 DeleteGuildEmoji {
953 /// The guild.
954 guild_id: GuildId,
955 /// The emoji.
956 emoji_id: EmojiId,
957 } => DELETE "/guilds/{guild_id}/emojis/{emoji_id}", major: guild_id;
958
959 /// [List Application Emojis](https://docs.discord.com/developers/resources/emoji#list-application-emojis).
960 ListApplicationEmojis {
961 /// The application.
962 application_id: ApplicationId,
963 } => GET "/applications/{application_id}/emojis";
964
965 /// [Get Application Emoji](https://docs.discord.com/developers/resources/emoji#get-application-emoji).
966 GetApplicationEmoji {
967 /// The application.
968 application_id: ApplicationId,
969 /// The emoji.
970 emoji_id: EmojiId,
971 } => GET "/applications/{application_id}/emojis/{emoji_id}";
972
973 /// [Create Application Emoji](https://docs.discord.com/developers/resources/emoji#create-application-emoji).
974 CreateApplicationEmoji {
975 /// The application.
976 application_id: ApplicationId,
977 } => POST "/applications/{application_id}/emojis";
978
979 /// [Modify Application Emoji](https://docs.discord.com/developers/resources/emoji#modify-application-emoji).
980 ModifyApplicationEmoji {
981 /// The application.
982 application_id: ApplicationId,
983 /// The emoji.
984 emoji_id: EmojiId,
985 } => PATCH "/applications/{application_id}/emojis/{emoji_id}";
986
987 /// [Delete Application Emoji](https://docs.discord.com/developers/resources/emoji#delete-application-emoji).
988 DeleteApplicationEmoji {
989 /// The application.
990 application_id: ApplicationId,
991 /// The emoji.
992 emoji_id: EmojiId,
993 } => DELETE "/applications/{application_id}/emojis/{emoji_id}";
994
995 // Stickers.
996
997 /// [Get Sticker](https://docs.discord.com/developers/resources/sticker#get-sticker).
998 GetSticker {
999 /// The sticker.
1000 sticker_id: StickerId,
1001 } => GET "/stickers/{sticker_id}";
1002
1003 /// [List Sticker Packs](https://docs.discord.com/developers/resources/sticker#list-sticker-packs).
1004 ListStickerPacks => GET "/sticker-packs";
1005
1006 /// [Get Sticker Pack](https://docs.discord.com/developers/resources/sticker#get-sticker-pack).
1007 GetStickerPack {
1008 /// The sticker pack.
1009 pack_id: StickerPackId,
1010 } => GET "/sticker-packs/{pack_id}";
1011
1012 /// [List Guild Stickers](https://docs.discord.com/developers/resources/sticker#list-guild-stickers).
1013 ListGuildStickers {
1014 /// The guild.
1015 guild_id: GuildId,
1016 } => GET "/guilds/{guild_id}/stickers", major: guild_id;
1017
1018 /// [Get Guild Sticker](https://docs.discord.com/developers/resources/sticker#get-guild-sticker).
1019 GetGuildSticker {
1020 /// The guild.
1021 guild_id: GuildId,
1022 /// The sticker.
1023 sticker_id: StickerId,
1024 } => GET "/guilds/{guild_id}/stickers/{sticker_id}", major: guild_id;
1025
1026 /// [Create Guild Sticker](https://docs.discord.com/developers/resources/sticker#create-guild-sticker).
1027 CreateGuildSticker {
1028 /// The guild.
1029 guild_id: GuildId,
1030 } => POST "/guilds/{guild_id}/stickers", major: guild_id;
1031
1032 /// [Modify Guild Sticker](https://docs.discord.com/developers/resources/sticker#modify-guild-sticker).
1033 ModifyGuildSticker {
1034 /// The guild.
1035 guild_id: GuildId,
1036 /// The sticker.
1037 sticker_id: StickerId,
1038 } => PATCH "/guilds/{guild_id}/stickers/{sticker_id}", major: guild_id;
1039
1040 /// [Delete Guild Sticker](https://docs.discord.com/developers/resources/sticker#delete-guild-sticker).
1041 DeleteGuildSticker {
1042 /// The guild.
1043 guild_id: GuildId,
1044 /// The sticker.
1045 sticker_id: StickerId,
1046 } => DELETE "/guilds/{guild_id}/stickers/{sticker_id}", major: guild_id;
1047
1048 // Soundboard.
1049
1050 /// [Send Soundboard Sound](https://docs.discord.com/developers/resources/soundboard#send-soundboard-sound).
1051 SendSoundboardSound {
1052 /// The voice channel.
1053 channel_id: ChannelId,
1054 } => POST "/channels/{channel_id}/send-soundboard-sound", major: channel_id;
1055
1056 /// [List Default Soundboard Sounds](https://docs.discord.com/developers/resources/soundboard#list-default-soundboard-sounds).
1057 ListDefaultSoundboardSounds => GET "/soundboard-default-sounds";
1058
1059 /// [List Guild Soundboard Sounds](https://docs.discord.com/developers/resources/soundboard#list-guild-soundboard-sounds).
1060 ListGuildSoundboardSounds {
1061 /// The guild.
1062 guild_id: GuildId,
1063 } => GET "/guilds/{guild_id}/soundboard-sounds", major: guild_id;
1064
1065 /// [Get Guild Soundboard Sound](https://docs.discord.com/developers/resources/soundboard#get-guild-soundboard-sound).
1066 GetGuildSoundboardSound {
1067 /// The guild.
1068 guild_id: GuildId,
1069 /// The sound.
1070 sound_id: SoundboardSoundId,
1071 } => GET "/guilds/{guild_id}/soundboard-sounds/{sound_id}", major: guild_id;
1072
1073 /// [Create Guild Soundboard Sound](https://docs.discord.com/developers/resources/soundboard#create-guild-soundboard-sound).
1074 CreateGuildSoundboardSound {
1075 /// The guild.
1076 guild_id: GuildId,
1077 } => POST "/guilds/{guild_id}/soundboard-sounds", major: guild_id;
1078
1079 /// [Modify Guild Soundboard Sound](https://docs.discord.com/developers/resources/soundboard#modify-guild-soundboard-sound).
1080 ModifyGuildSoundboardSound {
1081 /// The guild.
1082 guild_id: GuildId,
1083 /// The sound.
1084 sound_id: SoundboardSoundId,
1085 } => PATCH "/guilds/{guild_id}/soundboard-sounds/{sound_id}", major: guild_id;
1086
1087 /// [Delete Guild Soundboard Sound](https://docs.discord.com/developers/resources/soundboard#delete-guild-soundboard-sound).
1088 DeleteGuildSoundboardSound {
1089 /// The guild.
1090 guild_id: GuildId,
1091 /// The sound.
1092 sound_id: SoundboardSoundId,
1093 } => DELETE "/guilds/{guild_id}/soundboard-sounds/{sound_id}", major: guild_id;
1094
1095 // Guild scheduled events.
1096
1097 /// [List Scheduled Events for Guild](https://docs.discord.com/developers/resources/guild-scheduled-event#list-scheduled-events-for-guild).
1098 ListScheduledEventsForGuild {
1099 /// The guild.
1100 guild_id: GuildId,
1101 } => GET "/guilds/{guild_id}/scheduled-events", major: guild_id;
1102
1103 /// [Create Guild Scheduled Event](https://docs.discord.com/developers/resources/guild-scheduled-event#create-guild-scheduled-event).
1104 CreateGuildScheduledEvent {
1105 /// The guild.
1106 guild_id: GuildId,
1107 } => POST "/guilds/{guild_id}/scheduled-events", major: guild_id;
1108
1109 /// [Get Guild Scheduled Event](https://docs.discord.com/developers/resources/guild-scheduled-event#get-guild-scheduled-event).
1110 GetGuildScheduledEvent {
1111 /// The guild.
1112 guild_id: GuildId,
1113 /// The event.
1114 event_id: ScheduledEventId,
1115 } => GET "/guilds/{guild_id}/scheduled-events/{event_id}", major: guild_id;
1116
1117 /// [Modify Guild Scheduled Event](https://docs.discord.com/developers/resources/guild-scheduled-event#modify-guild-scheduled-event).
1118 ModifyGuildScheduledEvent {
1119 /// The guild.
1120 guild_id: GuildId,
1121 /// The event.
1122 event_id: ScheduledEventId,
1123 } => PATCH "/guilds/{guild_id}/scheduled-events/{event_id}", major: guild_id;
1124
1125 /// [Delete Guild Scheduled Event](https://docs.discord.com/developers/resources/guild-scheduled-event#delete-guild-scheduled-event).
1126 DeleteGuildScheduledEvent {
1127 /// The guild.
1128 guild_id: GuildId,
1129 /// The event.
1130 event_id: ScheduledEventId,
1131 } => DELETE "/guilds/{guild_id}/scheduled-events/{event_id}", major: guild_id;
1132
1133 /// [Get Guild Scheduled Event Users](https://docs.discord.com/developers/resources/guild-scheduled-event#get-guild-scheduled-event-users).
1134 GetGuildScheduledEventUsers {
1135 /// The guild.
1136 guild_id: GuildId,
1137 /// The event.
1138 event_id: ScheduledEventId,
1139 } => GET "/guilds/{guild_id}/scheduled-events/{event_id}/users", major: guild_id;
1140
1141 // Stage instances. The channel ID does not lead the path, so it is not a major parameter.
1142
1143 /// [Create Stage Instance](https://docs.discord.com/developers/resources/stage-instance#create-stage-instance).
1144 CreateStageInstance => POST "/stage-instances";
1145
1146 /// [Get Stage Instance](https://docs.discord.com/developers/resources/stage-instance#get-stage-instance).
1147 GetStageInstance {
1148 /// The stage channel.
1149 channel_id: ChannelId,
1150 } => GET "/stage-instances/{channel_id}";
1151
1152 /// [Modify Stage Instance](https://docs.discord.com/developers/resources/stage-instance#modify-stage-instance).
1153 ModifyStageInstance {
1154 /// The stage channel.
1155 channel_id: ChannelId,
1156 } => PATCH "/stage-instances/{channel_id}";
1157
1158 /// [Delete Stage Instance](https://docs.discord.com/developers/resources/stage-instance#delete-stage-instance).
1159 DeleteStageInstance {
1160 /// The stage channel.
1161 channel_id: ChannelId,
1162 } => DELETE "/stage-instances/{channel_id}";
1163
1164 // Invites. The invite code is part of the path but not a major parameter.
1165
1166 /// [Get Invite](https://docs.discord.com/developers/resources/invite#get-invite).
1167 GetInvite {
1168 /// The invite code.
1169 invite_code: &'a str,
1170 } => GET "/invites/{invite_code}";
1171
1172 /// [Delete Invite](https://docs.discord.com/developers/resources/invite#delete-invite).
1173 DeleteInvite {
1174 /// The invite code.
1175 invite_code: &'a str,
1176 } => DELETE "/invites/{invite_code}";
1177
1178 /// [Get Target Users](https://docs.discord.com/developers/resources/invite#get-target-users).
1179 GetTargetUsers {
1180 /// The invite code.
1181 invite_code: &'a str,
1182 } => GET "/invites/{invite_code}/target-users";
1183
1184 /// [Add Target User](https://docs.discord.com/developers/resources/invite#add-target-user).
1185 AddTargetUser {
1186 /// The invite code.
1187 invite_code: &'a str,
1188 /// The user.
1189 user_id: UserId,
1190 } => PUT "/invites/{invite_code}/target-users/{user_id}";
1191
1192 /// [Remove Target User](https://docs.discord.com/developers/resources/invite#remove-target-user).
1193 RemoveTargetUser {
1194 /// The invite code.
1195 invite_code: &'a str,
1196 /// The user.
1197 user_id: UserId,
1198 } => DELETE "/invites/{invite_code}/target-users/{user_id}";
1199
1200 /// [Update Target Users](https://docs.discord.com/developers/resources/invite#update-target-users).
1201 UpdateTargetUsers {
1202 /// The invite code.
1203 invite_code: &'a str,
1204 } => PUT "/invites/{invite_code}/target-users";
1205
1206 /// [Bulk-Add Target Users](https://docs.discord.com/developers/resources/invite#bulk-add-target-users).
1207 BulkAddTargetUsers {
1208 /// The invite code.
1209 invite_code: &'a str,
1210 } => POST "/invites/{invite_code}/target-users/bulk-add";
1211
1212 /// [Bulk-Delete Target Users](https://docs.discord.com/developers/resources/invite#bulk-delete-target-users).
1213 BulkDeleteTargetUsers {
1214 /// The invite code.
1215 invite_code: &'a str,
1216 } => POST "/invites/{invite_code}/target-users/bulk-delete";
1217
1218 /// [Get Target Users Job Status](https://docs.discord.com/developers/resources/invite#get-target-users-job-status).
1219 GetTargetUsersJobStatus {
1220 /// The invite code.
1221 invite_code: &'a str,
1222 } => GET "/invites/{invite_code}/target-users/job-status";
1223
1224 // Guild templates. `/guilds/templates/{template_code}` has no guild ID, so no major
1225 // parameter.
1226
1227 /// [Get Guild Template](https://docs.discord.com/developers/resources/guild-template#get-guild-template).
1228 GetGuildTemplate {
1229 /// The template code.
1230 template_code: &'a str,
1231 } => GET "/guilds/templates/{template_code}";
1232
1233 /// [Get Guild Templates](https://docs.discord.com/developers/resources/guild-template#get-guild-templates).
1234 GetGuildTemplates {
1235 /// The guild.
1236 guild_id: GuildId,
1237 } => GET "/guilds/{guild_id}/templates", major: guild_id;
1238
1239 /// [Create Guild Template](https://docs.discord.com/developers/resources/guild-template#create-guild-template).
1240 CreateGuildTemplate {
1241 /// The guild.
1242 guild_id: GuildId,
1243 } => POST "/guilds/{guild_id}/templates", major: guild_id;
1244
1245 /// [Sync Guild Template](https://docs.discord.com/developers/resources/guild-template#sync-guild-template).
1246 SyncGuildTemplate {
1247 /// The guild.
1248 guild_id: GuildId,
1249 /// The template code.
1250 template_code: &'a str,
1251 } => PUT "/guilds/{guild_id}/templates/{template_code}", major: guild_id;
1252
1253 /// [Modify Guild Template](https://docs.discord.com/developers/resources/guild-template#modify-guild-template).
1254 ModifyGuildTemplate {
1255 /// The guild.
1256 guild_id: GuildId,
1257 /// The template code.
1258 template_code: &'a str,
1259 } => PATCH "/guilds/{guild_id}/templates/{template_code}", major: guild_id;
1260
1261 /// [Delete Guild Template](https://docs.discord.com/developers/resources/guild-template#delete-guild-template).
1262 DeleteGuildTemplate {
1263 /// The guild.
1264 guild_id: GuildId,
1265 /// The template code.
1266 template_code: &'a str,
1267 } => DELETE "/guilds/{guild_id}/templates/{template_code}", major: guild_id;
1268
1269 // Audit log.
1270
1271 /// [Get Guild Audit Log](https://docs.discord.com/developers/resources/audit-log#get-guild-audit-log).
1272 GetGuildAuditLog {
1273 /// The guild.
1274 guild_id: GuildId,
1275 } => GET "/guilds/{guild_id}/audit-logs", major: guild_id;
1276
1277 // Polls.
1278
1279 /// [Get Answer Voters](https://docs.discord.com/developers/resources/poll#get-answer-voters).
1280 GetAnswerVoters {
1281 /// The channel.
1282 channel_id: ChannelId,
1283 /// The message with the poll.
1284 message_id: MessageId,
1285 /// The answer's [`answer_id`](djs_model::poll::Answer::answer_id).
1286 answer_id: u32,
1287 } => GET "/channels/{channel_id}/polls/{message_id}/answers/{answer_id}",
1288 major: channel_id;
1289 /// [End Poll](https://docs.discord.com/developers/resources/poll#end-poll).
1290 EndPoll {
1291 /// The channel.
1292 channel_id: ChannelId,
1293 /// The message with the poll.
1294 message_id: MessageId,
1295 } => POST "/channels/{channel_id}/polls/{message_id}/expire", major: channel_id;
1296
1297 // Voice.
1298
1299 /// [List Voice Regions](https://docs.discord.com/developers/resources/voice#list-voice-regions).
1300 ListVoiceRegions => GET "/voice/regions";
1301 /// [Get Current User Voice State](https://docs.discord.com/developers/resources/voice#get-current-user-voice-state).
1302 GetCurrentUserVoiceState {
1303 /// The guild.
1304 guild_id: GuildId,
1305 } => GET "/guilds/{guild_id}/voice-states/@me", major: guild_id;
1306 /// [Get User Voice State](https://docs.discord.com/developers/resources/voice#get-user-voice-state).
1307 GetUserVoiceState {
1308 /// The guild.
1309 guild_id: GuildId,
1310 /// The user.
1311 user_id: UserId,
1312 } => GET "/guilds/{guild_id}/voice-states/{user_id}", major: guild_id;
1313 /// [Modify Current User Voice State](https://docs.discord.com/developers/resources/voice#modify-current-user-voice-state).
1314 ModifyCurrentUserVoiceState {
1315 /// The guild.
1316 guild_id: GuildId,
1317 } => PATCH "/guilds/{guild_id}/voice-states/@me", major: guild_id;
1318 /// [Modify User Voice State](https://docs.discord.com/developers/resources/voice#modify-user-voice-state).
1319 ModifyUserVoiceState {
1320 /// The guild.
1321 guild_id: GuildId,
1322 /// The user.
1323 user_id: UserId,
1324 } => PATCH "/guilds/{guild_id}/voice-states/{user_id}", major: guild_id;
1325
1326 // Lobbies (Discord Social SDK).
1327
1328 /// [Create Lobby](https://docs.discord.com/developers/resources/lobby#create-lobby).
1329 CreateLobby => POST "/lobbies";
1330 /// [Create or Join Lobby](https://docs.discord.com/developers/resources/lobby#create-or-join-lobby).
1331 CreateOrJoinLobby => PUT "/lobbies";
1332 /// [Get Lobby](https://docs.discord.com/developers/resources/lobby#get-lobby).
1333 GetLobby {
1334 /// The lobby.
1335 lobby_id: LobbyId,
1336 } => GET "/lobbies/{lobby_id}";
1337 /// [Modify Lobby](https://docs.discord.com/developers/resources/lobby#modify-lobby).
1338 ModifyLobby {
1339 /// The lobby.
1340 lobby_id: LobbyId,
1341 } => PATCH "/lobbies/{lobby_id}";
1342 /// [Delete Lobby](https://docs.discord.com/developers/resources/lobby#delete-lobby).
1343 DeleteLobby {
1344 /// The lobby.
1345 lobby_id: LobbyId,
1346 } => DELETE "/lobbies/{lobby_id}";
1347 /// [Add a Member to a Lobby](https://docs.discord.com/developers/resources/lobby#add-a-member-to-a-lobby).
1348 AddLobbyMember {
1349 /// The lobby.
1350 lobby_id: LobbyId,
1351 /// The user.
1352 user_id: UserId,
1353 } => PUT "/lobbies/{lobby_id}/members/{user_id}";
1354 /// [Bulk Update Lobby Members](https://docs.discord.com/developers/resources/lobby#bulk-update-lobby-members).
1355 BulkUpdateLobbyMembers {
1356 /// The lobby.
1357 lobby_id: LobbyId,
1358 } => POST "/lobbies/{lobby_id}/members/bulk";
1359 /// [Remove a Member from a Lobby](https://docs.discord.com/developers/resources/lobby#remove-a-member-from-a-lobby).
1360 RemoveLobbyMember {
1361 /// The lobby.
1362 lobby_id: LobbyId,
1363 /// The user.
1364 user_id: UserId,
1365 } => DELETE "/lobbies/{lobby_id}/members/{user_id}";
1366 /// [Leave Lobby](https://docs.discord.com/developers/resources/lobby#leave-lobby).
1367 LeaveLobby {
1368 /// The lobby.
1369 lobby_id: LobbyId,
1370 } => DELETE "/lobbies/{lobby_id}/members/@me";
1371 /// [Link Channel to Lobby](https://docs.discord.com/developers/resources/lobby#link-channel-to-lobby).
1372 LinkChannelToLobby {
1373 /// The lobby.
1374 lobby_id: LobbyId,
1375 } => PATCH "/lobbies/{lobby_id}/channel-linking";
1376 /// [Unlink Channel from Lobby](https://docs.discord.com/developers/resources/lobby#unlink-channel-from-lobby).
1377 UnlinkChannelFromLobby {
1378 /// The lobby.
1379 lobby_id: LobbyId,
1380 } => PATCH "/lobbies/{lobby_id}/channel-linking";
1381 /// [Send Lobby Message](https://docs.discord.com/developers/resources/lobby#send-lobby-message).
1382 SendLobbyMessage {
1383 /// The lobby.
1384 lobby_id: LobbyId,
1385 } => POST "/lobbies/{lobby_id}/messages";
1386 /// [Get Lobby Messages](https://docs.discord.com/developers/resources/lobby#get-lobby-messages).
1387 GetLobbyMessages {
1388 /// The lobby.
1389 lobby_id: LobbyId,
1390 } => GET "/lobbies/{lobby_id}/messages";
1391 /// [Update Lobby Message Moderation Metadata](https://docs.discord.com/developers/resources/lobby#update-lobby-message-moderation-metadata).
1392 UpdateLobbyMessageModerationMetadata {
1393 /// The lobby.
1394 lobby_id: LobbyId,
1395 /// The lobby message.
1396 message_id: MessageId,
1397 } => PUT "/lobbies/{lobby_id}/messages/{message_id}/moderation-metadata";
1398 /// [Create Lobby Channel Invite for Self](https://docs.discord.com/developers/resources/lobby#create-lobby-channel-invite-for-self).
1399 CreateLobbyChannelInviteForSelf {
1400 /// The lobby.
1401 lobby_id: LobbyId,
1402 } => POST "/lobbies/{lobby_id}/members/@me/invites";
1403 /// [Create Lobby Channel Invite for User](https://docs.discord.com/developers/resources/lobby#create-lobby-channel-invite-for-user).
1404 CreateLobbyChannelInviteForUser {
1405 /// The lobby.
1406 lobby_id: LobbyId,
1407 /// The user.
1408 user_id: UserId,
1409 } => POST "/lobbies/{lobby_id}/members/{user_id}/invites";
1410
1411 // OAuth2.
1412
1413 /// [Get Current Bot Application Information](https://docs.discord.com/developers/topics/oauth2#get-current-bot-application-information).
1414 GetCurrentBotApplicationInformation => GET "/oauth2/applications/@me";
1415 /// [Get Current Authorization Information](https://docs.discord.com/developers/topics/oauth2#get-current-authorization-information).
1416 GetCurrentAuthorizationInformation => GET "/oauth2/@me";
1417 /// The [token URL](https://docs.discord.com/developers/topics/oauth2#shared-resources-oauth2-urls):
1418 /// exchanges an authorization code, a refresh token or the client credentials for an
1419 /// access token. Sent without the client's token (D-132).
1420 OAuth2TokenExchange => POST "/oauth2/token";
1421 /// The [token revocation URL](https://docs.discord.com/developers/topics/oauth2#authorization-code-grant-token-revocation-example).
1422 /// Sent without the client's token (D-132).
1423 OAuth2TokenRevocation => POST "/oauth2/token/revoke";
1424
1425 // Application identity profiles (game stats).
1426
1427 /// [Update Application Identity Profile](https://docs.discord.com/developers/resources/application-identity-profile#update-application-identity-profile).
1428 UpdateApplicationIdentityProfile {
1429 /// The application.
1430 application_id: ApplicationId,
1431 /// The Discord user.
1432 user_id: UserId,
1433 /// The user's ID in the app's system.
1434 provider_issued_user_id: &'a str,
1435 } => PATCH "/applications/{application_id}/users/{user_id}/identities/{provider_issued_user_id}/profile";
1436 /// [Get Application Identity Profile](https://docs.discord.com/developers/resources/application-identity-profile#get-application-identity-profile).
1437 GetApplicationIdentityProfile {
1438 /// The application.
1439 application_id: ApplicationId,
1440 /// The Discord user.
1441 user_id: UserId,
1442 /// The user's ID in the app's system.
1443 provider_issued_user_id: &'a str,
1444 } => GET "/applications/{application_id}/users/{user_id}/identities/{provider_issued_user_id}/profile";
1445 /// [Get Application Identities by User ID](https://docs.discord.com/developers/resources/application-identity-profile#get-application-identities-by-user-id).
1446 GetApplicationIdentitiesByUserId {
1447 /// The Discord user.
1448 user_id: UserId,
1449 /// The application.
1450 application_id: ApplicationId,
1451 } => GET "/users/{user_id}/application-identities/{application_id}";
1452 /// [Get Application Identities by External ID](https://docs.discord.com/developers/resources/application-identity-profile#get-application-identities-by-external-id).
1453 GetApplicationIdentitiesByExternalId {
1454 /// The application.
1455 application_id: ApplicationId,
1456 /// The external account provider type.
1457 provider_type: &'a str,
1458 /// The user's ID in the external system.
1459 provider_issued_user_id: &'a str,
1460 } => GET "/applications/{application_id}/application-identities/{provider_type}/{provider_issued_user_id}";
1461 /// [Delete Application Identity](https://docs.discord.com/developers/resources/application-identity-profile#delete-application-identity).
1462 DeleteApplicationIdentity {
1463 /// The Discord user.
1464 user_id: UserId,
1465 /// The application.
1466 application_id: ApplicationId,
1467 /// The external account provider type.
1468 provider_type: &'a str,
1469 /// The user's ID in the external system.
1470 provider_issued_user_id: &'a str,
1471 } => POST "/users/{user_id}/application-identities/{application_id}/{provider_type}/{provider_issued_user_id}/delete";
1472
1473 // Applications.
1474
1475 /// [Get Current Application](https://docs.discord.com/developers/resources/application#get-current-application).
1476 GetCurrentApplication => GET "/applications/@me";
1477 /// [Edit Current Application](https://docs.discord.com/developers/resources/application#edit-current-application).
1478 EditCurrentApplication => PATCH "/applications/@me";
1479 /// [Get Application Activity Instance](https://docs.discord.com/developers/resources/application#get-application-activity-instance).
1480 GetApplicationActivityInstance {
1481 /// The application.
1482 application_id: ApplicationId,
1483 /// The instance (`i-…`).
1484 instance_id: &'a str,
1485 } => GET "/applications/{application_id}/activity-instances/{instance_id}";
1486
1487 // Application role connection metadata.
1488
1489 /// [Get Application Role Connection Metadata Records](https://docs.discord.com/developers/resources/application-role-connection-metadata#get-application-role-connection-metadata-records).
1490 GetApplicationRoleConnectionMetadataRecords {
1491 /// The application.
1492 application_id: ApplicationId,
1493 } => GET "/applications/{application_id}/role-connections/metadata";
1494 /// [Update Application Role Connection Metadata Records](https://docs.discord.com/developers/resources/application-role-connection-metadata#update-application-role-connection-metadata-records).
1495 UpdateApplicationRoleConnectionMetadataRecords {
1496 /// The application.
1497 application_id: ApplicationId,
1498 } => PUT "/applications/{application_id}/role-connections/metadata";
1499
1500 // Monetization: SKUs, entitlements and subscriptions.
1501
1502 /// [List SKUs](https://docs.discord.com/developers/resources/sku#list-skus).
1503 ListSkus {
1504 /// The application.
1505 application_id: ApplicationId,
1506 } => GET "/applications/{application_id}/skus";
1507 /// [List Entitlements](https://docs.discord.com/developers/resources/entitlement#list-entitlements).
1508 ListEntitlements {
1509 /// The application.
1510 application_id: ApplicationId,
1511 } => GET "/applications/{application_id}/entitlements";
1512 /// [Get Entitlement](https://docs.discord.com/developers/resources/entitlement#get-entitlement).
1513 GetEntitlement {
1514 /// The application.
1515 application_id: ApplicationId,
1516 /// The entitlement.
1517 entitlement_id: EntitlementId,
1518 } => GET "/applications/{application_id}/entitlements/{entitlement_id}";
1519 /// [Consume an Entitlement](https://docs.discord.com/developers/resources/entitlement#consume-an-entitlement).
1520 ConsumeEntitlement {
1521 /// The application.
1522 application_id: ApplicationId,
1523 /// The entitlement.
1524 entitlement_id: EntitlementId,
1525 } => POST "/applications/{application_id}/entitlements/{entitlement_id}/consume";
1526 /// [Create Test Entitlement](https://docs.discord.com/developers/resources/entitlement#create-test-entitlement).
1527 CreateTestEntitlement {
1528 /// The application.
1529 application_id: ApplicationId,
1530 } => POST "/applications/{application_id}/entitlements";
1531 /// [Delete Test Entitlement](https://docs.discord.com/developers/resources/entitlement#delete-test-entitlement).
1532 DeleteTestEntitlement {
1533 /// The application.
1534 application_id: ApplicationId,
1535 /// The test entitlement.
1536 entitlement_id: EntitlementId,
1537 } => DELETE "/applications/{application_id}/entitlements/{entitlement_id}";
1538 /// [List SKU Subscriptions](https://docs.discord.com/developers/resources/subscription#list-sku-subscriptions).
1539 ListSkuSubscriptions {
1540 /// The SKU.
1541 sku_id: SkuId,
1542 } => GET "/skus/{sku_id}/subscriptions";
1543 /// [Get SKU Subscription](https://docs.discord.com/developers/resources/subscription#get-sku-subscription).
1544 GetSkuSubscription {
1545 /// The SKU.
1546 sku_id: SkuId,
1547 /// The subscription.
1548 subscription_id: SubscriptionId,
1549 } => GET "/skus/{sku_id}/subscriptions/{subscription_id}";
1550
1551 // Auto Moderation.
1552
1553 /// [List Auto Moderation Rules for Guild](https://docs.discord.com/developers/resources/auto-moderation#list-auto-moderation-rules-for-guild).
1554 ListAutoModerationRulesForGuild {
1555 /// The guild.
1556 guild_id: GuildId,
1557 } => GET "/guilds/{guild_id}/auto-moderation/rules", major: guild_id;
1558 /// [Get Auto Moderation Rule](https://docs.discord.com/developers/resources/auto-moderation#get-auto-moderation-rule).
1559 GetAutoModerationRule {
1560 /// The guild.
1561 guild_id: GuildId,
1562 /// The rule.
1563 rule_id: AutoModerationRuleId,
1564 } => GET "/guilds/{guild_id}/auto-moderation/rules/{rule_id}", major: guild_id;
1565 /// [Create Auto Moderation Rule](https://docs.discord.com/developers/resources/auto-moderation#create-auto-moderation-rule).
1566 CreateAutoModerationRule {
1567 /// The guild.
1568 guild_id: GuildId,
1569 } => POST "/guilds/{guild_id}/auto-moderation/rules", major: guild_id;
1570 /// [Modify Auto Moderation Rule](https://docs.discord.com/developers/resources/auto-moderation#modify-auto-moderation-rule).
1571 ModifyAutoModerationRule {
1572 /// The guild.
1573 guild_id: GuildId,
1574 /// The rule.
1575 rule_id: AutoModerationRuleId,
1576 } => PATCH "/guilds/{guild_id}/auto-moderation/rules/{rule_id}", major: guild_id;
1577 /// [Delete Auto Moderation Rule](https://docs.discord.com/developers/resources/auto-moderation#delete-auto-moderation-rule).
1578 DeleteAutoModerationRule {
1579 /// The guild.
1580 guild_id: GuildId,
1581 /// The rule.
1582 rule_id: AutoModerationRuleId,
1583 } => DELETE "/guilds/{guild_id}/auto-moderation/rules/{rule_id}", major: guild_id;
1584
1585 // Channels and threads.
1586
1587 /// [Get Channel](https://docs.discord.com/developers/resources/channel#get-channel).
1588 GetChannel {
1589 /// The channel.
1590 channel_id: ChannelId,
1591 } => GET "/channels/{channel_id}", major: channel_id;
1592
1593 /// [Modify Channel](https://docs.discord.com/developers/resources/channel#modify-channel).
1594 ModifyChannel {
1595 /// The channel.
1596 channel_id: ChannelId,
1597 } => PATCH "/channels/{channel_id}", major: channel_id;
1598
1599 /// [Delete/Close Channel](https://docs.discord.com/developers/resources/channel#deleteclose-channel).
1600 DeleteChannel {
1601 /// The channel.
1602 channel_id: ChannelId,
1603 } => DELETE "/channels/{channel_id}", major: channel_id;
1604
1605 /// [Get Channel Member Permissions](https://docs.discord.com/developers/resources/channel#get-channel-member-permissions).
1606 GetChannelMemberPermissions {
1607 /// The channel.
1608 channel_id: ChannelId,
1609 /// The user.
1610 user_id: UserId,
1611 } => GET "/channels/{channel_id}/permissions/member/{user_id}", major: channel_id;
1612
1613 /// [Get Channel Role Permissions](https://docs.discord.com/developers/resources/channel#get-channel-role-permissions).
1614 GetChannelRolePermissions {
1615 /// The channel.
1616 channel_id: ChannelId,
1617 /// The role.
1618 role_id: RoleId,
1619 } => GET "/channels/{channel_id}/permissions/role/{role_id}", major: channel_id;
1620
1621 /// [Set Voice Channel Status](https://docs.discord.com/developers/resources/channel#set-voice-channel-status).
1622 SetVoiceChannelStatus {
1623 /// The channel.
1624 channel_id: ChannelId,
1625 } => PUT "/channels/{channel_id}/voice-status", major: channel_id;
1626
1627 /// [Edit Channel Permissions](https://docs.discord.com/developers/resources/channel#edit-channel-permissions).
1628 EditChannelPermissions {
1629 /// The channel.
1630 channel_id: ChannelId,
1631 /// The role or user of the overwrite.
1632 overwrite_id: GenericId,
1633 } => PUT "/channels/{channel_id}/permissions/{overwrite_id}", major: channel_id;
1634
1635 /// [Delete Channel Permission](https://docs.discord.com/developers/resources/channel#delete-channel-permission).
1636 DeleteChannelPermission {
1637 /// The channel.
1638 channel_id: ChannelId,
1639 /// The role or user of the overwrite.
1640 overwrite_id: GenericId,
1641 } => DELETE "/channels/{channel_id}/permissions/{overwrite_id}", major: channel_id;
1642
1643 /// [Get Channel Invites](https://docs.discord.com/developers/resources/channel#get-channel-invites).
1644 GetChannelInvites {
1645 /// The channel.
1646 channel_id: ChannelId,
1647 } => GET "/channels/{channel_id}/invites", major: channel_id;
1648
1649 /// [Create Channel Invite](https://docs.discord.com/developers/resources/channel#create-channel-invite).
1650 CreateChannelInvite {
1651 /// The channel.
1652 channel_id: ChannelId,
1653 } => POST "/channels/{channel_id}/invites", major: channel_id;
1654
1655 /// [Follow Announcement Channel](https://docs.discord.com/developers/resources/channel#follow-announcement-channel).
1656 FollowAnnouncementChannel {
1657 /// The channel.
1658 channel_id: ChannelId,
1659 } => POST "/channels/{channel_id}/followers", major: channel_id;
1660
1661 /// [Trigger Typing Indicator](https://docs.discord.com/developers/resources/channel#trigger-typing-indicator).
1662 TriggerTypingIndicator {
1663 /// The channel.
1664 channel_id: ChannelId,
1665 } => POST "/channels/{channel_id}/typing", major: channel_id;
1666
1667 /// [Group DM Add Recipient](https://docs.discord.com/developers/resources/channel#group-dm-add-recipient).
1668 GroupDmAddRecipient {
1669 /// The channel.
1670 channel_id: ChannelId,
1671 /// The user.
1672 user_id: UserId,
1673 } => PUT "/channels/{channel_id}/recipients/{user_id}", major: channel_id;
1674
1675 /// [Group DM Remove Recipient](https://docs.discord.com/developers/resources/channel#group-dm-remove-recipient).
1676 GroupDmRemoveRecipient {
1677 /// The channel.
1678 channel_id: ChannelId,
1679 /// The user.
1680 user_id: UserId,
1681 } => DELETE "/channels/{channel_id}/recipients/{user_id}", major: channel_id;
1682
1683 /// [Start Thread from Message](https://docs.discord.com/developers/resources/channel#start-thread-from-message).
1684 StartThreadFromMessage {
1685 /// The channel.
1686 channel_id: ChannelId,
1687 /// The message the thread starts from.
1688 message_id: MessageId,
1689 } => POST "/channels/{channel_id}/messages/{message_id}/threads", major: channel_id;
1690
1691 /// [Start Thread without Message](https://docs.discord.com/developers/resources/channel#start-thread-without-message).
1692 StartThreadWithoutMessage {
1693 /// The channel.
1694 channel_id: ChannelId,
1695 } => POST "/channels/{channel_id}/threads", major: channel_id;
1696
1697 /// [Start Thread in Forum or Media Channel](https://docs.discord.com/developers/resources/channel#start-thread-in-forum-or-media-channel):
1698 /// the same endpoint as [`StartThreadWithoutMessage`](Self::StartThreadWithoutMessage), with
1699 /// a message body.
1700 StartThreadInForumOrMediaChannel {
1701 /// The channel.
1702 channel_id: ChannelId,
1703 } => POST "/channels/{channel_id}/threads", major: channel_id;
1704
1705 /// [Join Thread](https://docs.discord.com/developers/resources/channel#join-thread).
1706 JoinThread {
1707 /// The thread.
1708 channel_id: ChannelId,
1709 } => PUT "/channels/{channel_id}/thread-members/@me", major: channel_id;
1710
1711 /// [Add Thread Member](https://docs.discord.com/developers/resources/channel#add-thread-member).
1712 AddThreadMember {
1713 /// The thread.
1714 channel_id: ChannelId,
1715 /// The user.
1716 user_id: UserId,
1717 } => PUT "/channels/{channel_id}/thread-members/{user_id}", major: channel_id;
1718
1719 /// [Leave Thread](https://docs.discord.com/developers/resources/channel#leave-thread).
1720 LeaveThread {
1721 /// The thread.
1722 channel_id: ChannelId,
1723 } => DELETE "/channels/{channel_id}/thread-members/@me", major: channel_id;
1724
1725 /// [Remove Thread Member](https://docs.discord.com/developers/resources/channel#remove-thread-member).
1726 RemoveThreadMember {
1727 /// The thread.
1728 channel_id: ChannelId,
1729 /// The user.
1730 user_id: UserId,
1731 } => DELETE "/channels/{channel_id}/thread-members/{user_id}", major: channel_id;
1732
1733 /// [Get Thread Member](https://docs.discord.com/developers/resources/channel#get-thread-member).
1734 GetThreadMember {
1735 /// The thread.
1736 channel_id: ChannelId,
1737 /// The user.
1738 user_id: UserId,
1739 } => GET "/channels/{channel_id}/thread-members/{user_id}", major: channel_id;
1740
1741 /// [List Thread Members](https://docs.discord.com/developers/resources/channel#list-thread-members).
1742 ListThreadMembers {
1743 /// The thread.
1744 channel_id: ChannelId,
1745 } => GET "/channels/{channel_id}/thread-members", major: channel_id;
1746
1747 /// [List Public Archived Threads](https://docs.discord.com/developers/resources/channel#list-public-archived-threads).
1748 ListPublicArchivedThreads {
1749 /// The channel.
1750 channel_id: ChannelId,
1751 } => GET "/channels/{channel_id}/threads/archived/public", major: channel_id;
1752
1753 /// [List Private Archived Threads](https://docs.discord.com/developers/resources/channel#list-private-archived-threads).
1754 ListPrivateArchivedThreads {
1755 /// The channel.
1756 channel_id: ChannelId,
1757 } => GET "/channels/{channel_id}/threads/archived/private", major: channel_id;
1758
1759 /// [List Joined Private Archived Threads](https://docs.discord.com/developers/resources/channel#list-joined-private-archived-threads).
1760 ListJoinedPrivateArchivedThreads {
1761 /// The channel.
1762 channel_id: ChannelId,
1763 } => GET "/channels/{channel_id}/users/@me/threads/archived/private", major: channel_id;
1764
1765 // Messages.
1766
1767 /// [Get Channel Messages](https://docs.discord.com/developers/resources/message#get-channel-messages).
1768 GetChannelMessages {
1769 /// The channel.
1770 channel_id: ChannelId,
1771 } => GET "/channels/{channel_id}/messages", major: channel_id;
1772
1773 /// [Search Guild Messages](https://docs.discord.com/developers/resources/message#search-guild-messages).
1774 SearchGuildMessages {
1775 /// The guild.
1776 guild_id: GuildId,
1777 } => GET "/guilds/{guild_id}/messages/search", major: guild_id;
1778
1779 /// [Get Channel Message](https://docs.discord.com/developers/resources/message#get-channel-message).
1780 GetChannelMessage {
1781 /// The channel.
1782 channel_id: ChannelId,
1783 /// The message.
1784 message_id: MessageId,
1785 } => GET "/channels/{channel_id}/messages/{message_id}", major: channel_id;
1786
1787 /// [Create Message](https://docs.discord.com/developers/resources/message#create-message).
1788 CreateMessage {
1789 /// The channel to send the message in.
1790 channel_id: ChannelId,
1791 } => POST "/channels/{channel_id}/messages", major: channel_id;
1792
1793 /// [Crosspost Message](https://docs.discord.com/developers/resources/message#crosspost-message).
1794 CrosspostMessage {
1795 /// The announcement channel.
1796 channel_id: ChannelId,
1797 /// The message to publish.
1798 message_id: MessageId,
1799 } => POST "/channels/{channel_id}/messages/{message_id}/crosspost", major: channel_id;
1800
1801 /// [Create Reaction](https://docs.discord.com/developers/resources/message#create-reaction).
1802 CreateReaction {
1803 /// The channel.
1804 channel_id: ChannelId,
1805 /// The message.
1806 message_id: MessageId,
1807 /// The emoji.
1808 emoji: ReactionEmoji<'a>,
1809 } => PUT "/channels/{channel_id}/messages/{message_id}/reactions/{emoji}/@me",
1810 major: channel_id;
1811
1812 /// [Delete Own Reaction](https://docs.discord.com/developers/resources/message#delete-own-reaction).
1813 DeleteOwnReaction {
1814 /// The channel.
1815 channel_id: ChannelId,
1816 /// The message.
1817 message_id: MessageId,
1818 /// The emoji.
1819 emoji: ReactionEmoji<'a>,
1820 } => DELETE "/channels/{channel_id}/messages/{message_id}/reactions/{emoji}/@me",
1821 major: channel_id;
1822
1823 /// [Delete User Reaction](https://docs.discord.com/developers/resources/message#delete-user-reaction).
1824 DeleteUserReaction {
1825 /// The channel.
1826 channel_id: ChannelId,
1827 /// The message.
1828 message_id: MessageId,
1829 /// The emoji.
1830 emoji: ReactionEmoji<'a>,
1831 /// The user whose reaction is removed.
1832 user_id: UserId,
1833 } => DELETE "/channels/{channel_id}/messages/{message_id}/reactions/{emoji}/{user_id}",
1834 major: channel_id;
1835
1836 /// [Get Reactions](https://docs.discord.com/developers/resources/message#get-reactions).
1837 GetReactions {
1838 /// The channel.
1839 channel_id: ChannelId,
1840 /// The message.
1841 message_id: MessageId,
1842 /// The emoji.
1843 emoji: ReactionEmoji<'a>,
1844 } => GET "/channels/{channel_id}/messages/{message_id}/reactions/{emoji}",
1845 major: channel_id;
1846
1847 /// [Delete All Reactions](https://docs.discord.com/developers/resources/message#delete-all-reactions).
1848 DeleteAllReactions {
1849 /// The channel.
1850 channel_id: ChannelId,
1851 /// The message.
1852 message_id: MessageId,
1853 } => DELETE "/channels/{channel_id}/messages/{message_id}/reactions", major: channel_id;
1854
1855 /// [Delete All Reactions for Emoji](https://docs.discord.com/developers/resources/message#delete-all-reactions-for-emoji).
1856 DeleteAllReactionsForEmoji {
1857 /// The channel.
1858 channel_id: ChannelId,
1859 /// The message.
1860 message_id: MessageId,
1861 /// The emoji.
1862 emoji: ReactionEmoji<'a>,
1863 } => DELETE "/channels/{channel_id}/messages/{message_id}/reactions/{emoji}",
1864 major: channel_id;
1865
1866 /// [Edit Message](https://docs.discord.com/developers/resources/message#edit-message).
1867 EditMessage {
1868 /// The channel.
1869 channel_id: ChannelId,
1870 /// The message.
1871 message_id: MessageId,
1872 } => PATCH "/channels/{channel_id}/messages/{message_id}", major: channel_id;
1873
1874 /// [Delete Message](https://docs.discord.com/developers/resources/message#delete-message).
1875 /// Messages older than two weeks are deleted under a separate rate limit.
1876 DeleteMessage {
1877 /// The channel of the message.
1878 channel_id: ChannelId,
1879 /// The message to delete.
1880 message_id: MessageId,
1881 } => DELETE "/channels/{channel_id}/messages/{message_id}", major: channel_id;
1882
1883 /// [Bulk Delete Messages](https://docs.discord.com/developers/resources/message#bulk-delete-messages).
1884 BulkDeleteMessages {
1885 /// The channel.
1886 channel_id: ChannelId,
1887 } => POST "/channels/{channel_id}/messages/bulk-delete", major: channel_id;
1888
1889 /// [Get Channel Pins](https://docs.discord.com/developers/resources/message#get-channel-pins).
1890 GetChannelPins {
1891 /// The channel.
1892 channel_id: ChannelId,
1893 } => GET "/channels/{channel_id}/messages/pins", major: channel_id;
1894
1895 /// [Pin Message](https://docs.discord.com/developers/resources/message#pin-message).
1896 PinMessage {
1897 /// The channel.
1898 channel_id: ChannelId,
1899 /// The message.
1900 message_id: MessageId,
1901 } => PUT "/channels/{channel_id}/messages/pins/{message_id}", major: channel_id;
1902
1903 /// [Unpin Message](https://docs.discord.com/developers/resources/message#unpin-message).
1904 UnpinMessage {
1905 /// The channel.
1906 channel_id: ChannelId,
1907 /// The message.
1908 message_id: MessageId,
1909 } => DELETE "/channels/{channel_id}/messages/pins/{message_id}", major: channel_id;
1910
1911 /// [Create Interaction Response](https://docs.discord.com/developers/interactions/receiving-and-responding#create-interaction-response):
1912 /// the initial response to an interaction (within 3 seconds). Not bound to the global rate
1913 /// limit, and never queued behind other callbacks.
1914 CreateInteractionResponse {
1915 /// The interaction.
1916 interaction_id: InteractionId,
1917 /// The interaction's token.
1918 interaction_token: &'a str,
1919 } => POST "/interactions/{interaction_id}/{interaction_token}/callback",
1920 limits: INTERACTION_CALLBACK;
1921
1922 /// [Get Original Interaction Response](https://docs.discord.com/developers/interactions/receiving-and-responding#get-original-interaction-response).
1923 GetOriginalInteractionResponse {
1924 /// The application.
1925 application_id: ApplicationId,
1926 /// The interaction's token.
1927 interaction_token: &'a str,
1928 } => GET "/webhooks/{application_id}/{interaction_token}/messages/@original",
1929 major: application_id interaction_token, limits: INTERACTION;
1930
1931 /// [Edit Original Interaction Response](https://docs.discord.com/developers/interactions/receiving-and-responding#edit-original-interaction-response).
1932 EditOriginalInteractionResponse {
1933 /// The application.
1934 application_id: ApplicationId,
1935 /// The interaction's token.
1936 interaction_token: &'a str,
1937 } => PATCH "/webhooks/{application_id}/{interaction_token}/messages/@original",
1938 major: application_id interaction_token, limits: INTERACTION;
1939
1940 /// [Delete Original Interaction Response](https://docs.discord.com/developers/interactions/receiving-and-responding#delete-original-interaction-response).
1941 DeleteOriginalInteractionResponse {
1942 /// The application.
1943 application_id: ApplicationId,
1944 /// The interaction's token.
1945 interaction_token: &'a str,
1946 } => DELETE "/webhooks/{application_id}/{interaction_token}/messages/@original",
1947 major: application_id interaction_token, limits: INTERACTION;
1948
1949 /// [Create Followup Message](https://docs.discord.com/developers/interactions/receiving-and-responding#create-followup-message).
1950 CreateFollowupMessage {
1951 /// The application.
1952 application_id: ApplicationId,
1953 /// The interaction's token.
1954 interaction_token: &'a str,
1955 } => POST "/webhooks/{application_id}/{interaction_token}",
1956 major: application_id interaction_token, limits: INTERACTION;
1957
1958 /// [Get Followup Message](https://docs.discord.com/developers/interactions/receiving-and-responding#get-followup-message).
1959 GetFollowupMessage {
1960 /// The application.
1961 application_id: ApplicationId,
1962 /// The interaction's token.
1963 interaction_token: &'a str,
1964 /// The follow-up message.
1965 message_id: MessageId,
1966 } => GET "/webhooks/{application_id}/{interaction_token}/messages/{message_id}",
1967 major: application_id interaction_token, limits: INTERACTION;
1968
1969 /// [Edit Followup Message](https://docs.discord.com/developers/interactions/receiving-and-responding#edit-followup-message).
1970 EditFollowupMessage {
1971 /// The application.
1972 application_id: ApplicationId,
1973 /// The interaction's token.
1974 interaction_token: &'a str,
1975 /// The follow-up message.
1976 message_id: MessageId,
1977 } => PATCH "/webhooks/{application_id}/{interaction_token}/messages/{message_id}",
1978 major: application_id interaction_token, limits: INTERACTION;
1979
1980 /// [Delete Followup Message](https://docs.discord.com/developers/interactions/receiving-and-responding#delete-followup-message).
1981 DeleteFollowupMessage {
1982 /// The application.
1983 application_id: ApplicationId,
1984 /// The interaction's token.
1985 interaction_token: &'a str,
1986 /// The follow-up message.
1987 message_id: MessageId,
1988 } => DELETE "/webhooks/{application_id}/{interaction_token}/messages/{message_id}",
1989 major: application_id interaction_token, limits: INTERACTION;
1990
1991 // Application commands. The guild ID is not a major parameter here: Discord's major
1992 // parameters only lead a path (`/guilds/{guild_id}/...`), as discord.js also assumes.
1993
1994 /// [Get Global Application Commands](https://docs.discord.com/developers/interactions/application-commands#get-global-application-commands).
1995 GetGlobalApplicationCommands {
1996 /// The application.
1997 application_id: ApplicationId,
1998 } => GET "/applications/{application_id}/commands";
1999
2000 /// [Create Global Application Command](https://docs.discord.com/developers/interactions/application-commands#create-global-application-command).
2001 CreateGlobalApplicationCommand {
2002 /// The application.
2003 application_id: ApplicationId,
2004 } => POST "/applications/{application_id}/commands";
2005
2006 /// [Get Global Application Command](https://docs.discord.com/developers/interactions/application-commands#get-global-application-command).
2007 GetGlobalApplicationCommand {
2008 /// The application.
2009 application_id: ApplicationId,
2010 /// The command.
2011 command_id: CommandId,
2012 } => GET "/applications/{application_id}/commands/{command_id}";
2013
2014 /// [Edit Global Application Command](https://docs.discord.com/developers/interactions/application-commands#edit-global-application-command).
2015 EditGlobalApplicationCommand {
2016 /// The application.
2017 application_id: ApplicationId,
2018 /// The command.
2019 command_id: CommandId,
2020 } => PATCH "/applications/{application_id}/commands/{command_id}";
2021
2022 /// [Delete Global Application Command](https://docs.discord.com/developers/interactions/application-commands#delete-global-application-command).
2023 DeleteGlobalApplicationCommand {
2024 /// The application.
2025 application_id: ApplicationId,
2026 /// The command.
2027 command_id: CommandId,
2028 } => DELETE "/applications/{application_id}/commands/{command_id}";
2029
2030 /// [Bulk Overwrite Global Application Commands](https://docs.discord.com/developers/interactions/application-commands#bulk-overwrite-global-application-commands).
2031 BulkOverwriteGlobalApplicationCommands {
2032 /// The application.
2033 application_id: ApplicationId,
2034 } => PUT "/applications/{application_id}/commands";
2035
2036 /// [Get Guild Application Commands](https://docs.discord.com/developers/interactions/application-commands#get-guild-application-commands).
2037 GetGuildApplicationCommands {
2038 /// The application.
2039 application_id: ApplicationId,
2040 /// The guild.
2041 guild_id: GuildId,
2042 } => GET "/applications/{application_id}/guilds/{guild_id}/commands";
2043
2044 /// [Create Guild Application Command](https://docs.discord.com/developers/interactions/application-commands#create-guild-application-command).
2045 CreateGuildApplicationCommand {
2046 /// The application.
2047 application_id: ApplicationId,
2048 /// The guild.
2049 guild_id: GuildId,
2050 } => POST "/applications/{application_id}/guilds/{guild_id}/commands";
2051
2052 /// [Get Guild Application Command](https://docs.discord.com/developers/interactions/application-commands#get-guild-application-command).
2053 GetGuildApplicationCommand {
2054 /// The application.
2055 application_id: ApplicationId,
2056 /// The guild.
2057 guild_id: GuildId,
2058 /// The command.
2059 command_id: CommandId,
2060 } => GET "/applications/{application_id}/guilds/{guild_id}/commands/{command_id}";
2061
2062 /// [Edit Guild Application Command](https://docs.discord.com/developers/interactions/application-commands#edit-guild-application-command).
2063 EditGuildApplicationCommand {
2064 /// The application.
2065 application_id: ApplicationId,
2066 /// The guild.
2067 guild_id: GuildId,
2068 /// The command.
2069 command_id: CommandId,
2070 } => PATCH "/applications/{application_id}/guilds/{guild_id}/commands/{command_id}";
2071
2072 /// [Delete Guild Application Command](https://docs.discord.com/developers/interactions/application-commands#delete-guild-application-command).
2073 DeleteGuildApplicationCommand {
2074 /// The application.
2075 application_id: ApplicationId,
2076 /// The guild.
2077 guild_id: GuildId,
2078 /// The command.
2079 command_id: CommandId,
2080 } => DELETE "/applications/{application_id}/guilds/{guild_id}/commands/{command_id}";
2081
2082 /// [Bulk Overwrite Guild Application Commands](https://docs.discord.com/developers/interactions/application-commands#bulk-overwrite-guild-application-commands).
2083 BulkOverwriteGuildApplicationCommands {
2084 /// The application.
2085 application_id: ApplicationId,
2086 /// The guild.
2087 guild_id: GuildId,
2088 } => PUT "/applications/{application_id}/guilds/{guild_id}/commands";
2089
2090 /// [Get Guild Application Command Permissions](https://docs.discord.com/developers/interactions/application-commands#get-guild-application-command-permissions).
2091 GetGuildApplicationCommandPermissions {
2092 /// The application.
2093 application_id: ApplicationId,
2094 /// The guild.
2095 guild_id: GuildId,
2096 } => GET "/applications/{application_id}/guilds/{guild_id}/commands/permissions";
2097
2098 /// [Get Application Command Permissions](https://docs.discord.com/developers/interactions/application-commands#get-application-command-permissions).
2099 GetApplicationCommandPermissions {
2100 /// The application.
2101 application_id: ApplicationId,
2102 /// The guild.
2103 guild_id: GuildId,
2104 /// The command.
2105 command_id: CommandId,
2106 } => GET "/applications/{application_id}/guilds/{guild_id}/commands/{command_id}/permissions";
2107
2108 /// [Edit Application Command Permissions](https://docs.discord.com/developers/interactions/application-commands#edit-application-command-permissions):
2109 /// needs a Bearer token of a user who can manage the guild and the command.
2110 EditApplicationCommandPermissions {
2111 /// The application.
2112 application_id: ApplicationId,
2113 /// The guild.
2114 guild_id: GuildId,
2115 /// The command.
2116 command_id: CommandId,
2117 } => PUT "/applications/{application_id}/guilds/{guild_id}/commands/{command_id}/permissions";
2118}
2119
2120#[cfg(test)]
2121mod tests {
2122 use super::*;
2123
2124 const TOKEN: &str = "aW50ZXJhY3Rpb24";
2125
2126 #[test]
2127 fn paths() {
2128 assert_eq!(Route::GetGatewayBot.path(), "/gateway/bot");
2129 assert_eq!(
2130 Route::CreateMessage {
2131 channel_id: ChannelId::new(1)
2132 }
2133 .path(),
2134 "/channels/1/messages"
2135 );
2136 assert_eq!(
2137 Route::CreateInteractionResponse {
2138 interaction_id: InteractionId::new(2),
2139 interaction_token: TOKEN,
2140 }
2141 .path(),
2142 "/interactions/2/aW50ZXJhY3Rpb24/callback"
2143 );
2144 assert_eq!(
2145 Route::EditFollowupMessage {
2146 application_id: ApplicationId::new(3),
2147 interaction_token: TOKEN,
2148 message_id: MessageId::new(4),
2149 }
2150 .path(),
2151 "/webhooks/3/aW50ZXJhY3Rpb24/messages/4"
2152 );
2153 }
2154
2155 #[test]
2156 fn text_parameters_cannot_change_the_path() {
2157 let route = Route::CreateFollowupMessage {
2158 application_id: ApplicationId::new(3),
2159 interaction_token: "a/../b?c=d#e f%",
2160 };
2161 assert_eq!(route.path(), "/webhooks/3/a%2F..%2Fb%3Fc%3Dd%23e%20f%25");
2162 }
2163
2164 #[test]
2165 fn debug_redacts_tokens() {
2166 let route = Route::GetFollowupMessage {
2167 application_id: ApplicationId::new(3),
2168 interaction_token: TOKEN,
2169 message_id: MessageId::new(4),
2170 };
2171 let debug = format!("{route:?}");
2172 assert_eq!(
2173 debug,
2174 r#"GetFollowupMessage { application_id: 3, interaction_token: "<redacted>", message_id: 4 }"#
2175 );
2176 assert_eq!(format!("{:?}", Route::GetGatewayBot), "GetGatewayBot");
2177 }
2178
2179 #[test]
2180 fn token_routes_are_not_authenticated_with_the_client_token() {
2181 let webhook = WebhookId::new(1);
2182 assert!(
2183 Route::GetWebhook {
2184 webhook_id: webhook
2185 }
2186 .authenticated()
2187 );
2188 assert!(
2189 !Route::ExecuteWebhook {
2190 webhook_id: webhook,
2191 webhook_token: TOKEN
2192 }
2193 .authenticated()
2194 );
2195 assert!(
2196 !Route::CreateInteractionResponse {
2197 interaction_id: InteractionId::new(2),
2198 interaction_token: TOKEN
2199 }
2200 .authenticated()
2201 );
2202 assert!(Route::GetGatewayBot.authenticated());
2203 assert!(!Route::OAuth2TokenExchange.authenticated());
2204 assert!(!Route::OAuth2TokenRevocation.authenticated());
2205 assert!(Route::GetCurrentAuthorizationInformation.authenticated());
2206 }
2207
2208 #[test]
2209 fn major_parameter() {
2210 let a = Route::CreateMessage {
2211 channel_id: ChannelId::new(1),
2212 }
2213 .bucket();
2214 let b = Route::CreateMessage {
2215 channel_id: ChannelId::new(2),
2216 }
2217 .bucket();
2218 assert_eq!(a.template, b.template);
2219 assert_ne!(a.major, b.major);
2220 assert_eq!(a.template, "POST /channels/{channel_id}/messages");
2221 assert_eq!(Route::GetGatewayBot.bucket().major, 0);
2222
2223 // Webhook routes are limited per webhook ID + token.
2224 let followup = |token| {
2225 Route::CreateFollowupMessage {
2226 application_id: ApplicationId::new(3),
2227 interaction_token: token,
2228 }
2229 .bucket()
2230 };
2231 assert_ne!(followup("a").major, followup("b").major);
2232 assert_eq!(followup("a").major, followup("a").major);
2233
2234 // A guild ID inside an application path is not a major parameter.
2235 let guild_command = |guild| {
2236 Route::CreateGuildApplicationCommand {
2237 application_id: ApplicationId::new(3),
2238 guild_id: GuildId::new(guild),
2239 }
2240 .bucket()
2241 };
2242 assert_eq!(guild_command(4), guild_command(5));
2243 assert_eq!(guild_command(4).major, 0);
2244 }
2245
2246 #[test]
2247 fn old_message_deletes_have_their_own_bucket() {
2248 let created_ms = 1_794_398_400_000;
2249 let route = Route::DeleteMessage {
2250 channel_id: ChannelId::new(1),
2251 message_id: MessageId::from_timestamp_ms(created_ms).unwrap(),
2252 };
2253 assert_eq!(
2254 route.path(),
2255 format!(
2256 "/channels/1/messages/{}",
2257 MessageId::from_timestamp_ms(created_ms).unwrap()
2258 )
2259 );
2260 let new = route.bucket_at(created_ms + OLD_MESSAGE_AGE_MS);
2261 assert_eq!(
2262 new.template,
2263 "DELETE /channels/{channel_id}/messages/{message_id}"
2264 );
2265 let old = route.bucket_at(created_ms + OLD_MESSAGE_AGE_MS + 1);
2266 assert_eq!(old.template, OLD_MESSAGE_DELETE);
2267 // Same channel: the major parameter does not change.
2268 assert_eq!((old.major, old.limits), (new.major, new.limits));
2269 // A clock before the message (or before 1970) never makes it old.
2270 assert_eq!(route.bucket_at(0).template, new.template);
2271 // With the real clock, a message from 2015 is old.
2272 let ancient = Route::DeleteMessage {
2273 channel_id: ChannelId::new(1),
2274 message_id: MessageId::new(1 << 22),
2275 };
2276 assert_eq!(ancient.bucket().template, OLD_MESSAGE_DELETE);
2277 }
2278
2279 #[test]
2280 fn interaction_routes_are_not_global() {
2281 let callback = Route::CreateInteractionResponse {
2282 interaction_id: InteractionId::new(2),
2283 interaction_token: TOKEN,
2284 }
2285 .bucket();
2286 assert_eq!(callback.limits, Limits::INTERACTION_CALLBACK);
2287 assert!(!callback.limits.global && callback.limits.burst);
2288 let original = Route::GetOriginalInteractionResponse {
2289 application_id: ApplicationId::new(3),
2290 interaction_token: TOKEN,
2291 }
2292 .bucket();
2293 assert!(!original.limits.global && !original.limits.burst);
2294 assert!(Route::GetGatewayBot.bucket().limits.global);
2295 }
2296}