twilight_http/client/mod.rs
1mod builder;
2pub(crate) mod connector;
3mod interaction;
4
5pub use self::{builder::ClientBuilder, interaction::InteractionClient};
6
7use crate::request::{
8 application::{
9 emoji::{
10 AddApplicationEmoji, DeleteApplicationEmoji, ListApplicationEmojis,
11 UpdateApplicationEmoji,
12 },
13 monetization::{
14 ConsumeEntitlement, CreateTestEntitlement, CreateTestEntitlementOwner,
15 DeleteTestEntitlement, GetEntitlement, GetEntitlements, GetSKUSubscription,
16 GetSKUSubscriptions, GetSKUs,
17 },
18 },
19 channel::{GetChannelMemberPermissions, GetChannelRolePermissions},
20 guild::{
21 ban::BulkGuildBan,
22 member::GetGuildMemberPermissions,
23 message::search_guild_messages::SearchGuildMessages,
24 role::GetGuildRolePermissions,
25 user::{GetCurrentUserVoiceState, GetUserVoiceState},
26 },
27 sticker::GetStickerPack,
28};
29#[allow(deprecated)]
30use crate::{
31 API_VERSION,
32 client::connector::Connector,
33 error::{Error, ErrorType},
34 request::{
35 GetCurrentAuthorizationInformation, GetGateway, GetUserApplicationInfo, GetVoiceRegions,
36 Method, Request, UpdateCurrentUserApplication,
37 channel::{
38 CreatePin, CreateTypingTrigger, DeleteChannel, DeleteChannelPermission, DeletePin,
39 FollowNewsChannel, GetChannel, GetPins, UpdateChannel, UpdateChannelPermission,
40 invite::{CreateInvite, DeleteInvite, GetChannelInvites, GetInvite},
41 message::{
42 CreateMessage, CrosspostMessage, DeleteMessage, DeleteMessages, GetChannelMessages,
43 GetMessage, UpdateMessage,
44 },
45 reaction::{
46 CreateReaction, DeleteAllReaction, DeleteAllReactions, DeleteReaction,
47 GetReactions, RequestReactionType, delete_reaction::TargetUser,
48 },
49 stage::{
50 CreateStageInstance, DeleteStageInstance, GetStageInstance, UpdateStageInstance,
51 },
52 thread::{
53 AddThreadMember, CreateForumThread, CreateThread, CreateThreadFromMessage,
54 GetJoinedPrivateArchivedThreads, GetPrivateArchivedThreads,
55 GetPublicArchivedThreads, GetThreadMember, GetThreadMembers, JoinThread,
56 LeaveThread, RemoveThreadMember, UpdateThread,
57 },
58 webhook::{
59 CreateWebhook, DeleteWebhook, DeleteWebhookMessage, ExecuteWebhook,
60 GetChannelWebhooks, GetWebhook, GetWebhookMessage, UpdateWebhook,
61 UpdateWebhookMessage, UpdateWebhookWithToken,
62 },
63 },
64 guild::{
65 CreateGuildChannel, CreateGuildPrune, DeleteGuild, GetActiveThreads, GetAuditLog,
66 GetGuild, GetGuildChannels, GetGuildInvites, GetGuildOnboarding, GetGuildPreview,
67 GetGuildPruneCount, GetGuildVanityUrl, GetGuildVoiceRegions, GetGuildWebhooks,
68 GetGuildWelcomeScreen, GetGuildWidget, GetGuildWidgetSettings, UpdateCurrentMember,
69 UpdateGuild, UpdateGuildChannelPositions, UpdateGuildMfa, UpdateGuildWelcomeScreen,
70 UpdateGuildWidgetSettings,
71 auto_moderation::{
72 CreateAutoModerationRule, DeleteAutoModerationRule, GetAutoModerationRule,
73 GetGuildAutoModerationRules, UpdateAutoModerationRule,
74 },
75 ban::{CreateBan, DeleteBan, GetBan, GetBans},
76 emoji::{CreateEmoji, DeleteEmoji, GetEmoji, GetEmojis, UpdateEmoji},
77 integration::{DeleteGuildIntegration, GetGuildIntegrations},
78 member::{
79 AddGuildMember, AddRoleToMember, GetGuildMembers, GetMember, RemoveMember,
80 RemoveRoleFromMember, SearchGuildMembers, UpdateGuildMember,
81 },
82 role::{
83 CreateRole, DeleteRole, GetGuildRoleMemberCounts, GetGuildRoles, GetRole,
84 UpdateRole, UpdateRolePositions,
85 },
86 sticker::{
87 CreateGuildSticker, DeleteGuildSticker, GetGuildSticker, GetGuildStickers,
88 UpdateGuildSticker,
89 },
90 update_guild_onboarding::{UpdateGuildOnboarding, UpdateGuildOnboardingFields},
91 user::{UpdateCurrentUserVoiceState, UpdateUserVoiceState},
92 },
93 poll::{EndPoll, GetAnswerVoters},
94 scheduled_event::{
95 CreateGuildScheduledEvent, DeleteGuildScheduledEvent, GetGuildScheduledEvent,
96 GetGuildScheduledEventUsers, GetGuildScheduledEvents, UpdateGuildScheduledEvent,
97 },
98 sticker::{GetNitroStickerPacks, GetSticker},
99 template::{
100 CreateGuildFromTemplate, CreateTemplate, DeleteTemplate, GetTemplate, GetTemplates,
101 SyncTemplate, UpdateTemplate,
102 },
103 user::{
104 CreatePrivateChannel, GetCurrentUser, GetCurrentUserConnections,
105 GetCurrentUserGuildMember, GetCurrentUserGuilds, GetUser, LeaveGuild,
106 UpdateCurrentUser,
107 },
108 },
109 response::ResponseFuture,
110};
111use http::header::{
112 AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, HeaderMap, HeaderValue, USER_AGENT,
113};
114use http_body_util::Full;
115use hyper::body::Bytes;
116use hyper_util::client::legacy::Client as HyperClient;
117use std::{
118 fmt::{Debug, Formatter, Result as FmtResult},
119 ops::Deref,
120 sync::{
121 Arc,
122 atomic::{AtomicBool, Ordering},
123 },
124 time::Duration,
125};
126use twilight_http_ratelimiting::{Endpoint, RateLimiter};
127use twilight_model::{
128 channel::{ChannelType, message::AllowedMentions},
129 guild::{
130 MfaLevel, RolePosition, auto_moderation::AutoModerationEventType,
131 scheduled_event::PrivacyLevel,
132 },
133 http::{channel_position::Position, permission_overwrite::PermissionOverwrite},
134 id::{
135 Id,
136 marker::{
137 ApplicationMarker, AutoModerationRuleMarker, ChannelMarker, EmojiMarker,
138 EntitlementMarker, GuildMarker, IntegrationMarker, MessageMarker, RoleMarker,
139 ScheduledEventMarker, SkuMarker, StickerMarker, StickerPackMarker, SubscriptionMarker,
140 UserMarker, WebhookMarker,
141 },
142 },
143};
144
145const TWILIGHT_USER_AGENT: &str = concat!(
146 "DiscordBot (",
147 env!("CARGO_PKG_HOMEPAGE"),
148 ", ",
149 env!("CARGO_PKG_VERSION"),
150 ") Twilight-rs",
151);
152
153/// Wrapper for an authorization token with a debug implementation that redacts
154/// the string.
155#[derive(Default)]
156struct Token {
157 /// Authorization token that is redacted in the Debug implementation.
158 inner: Box<str>,
159}
160
161impl Token {
162 /// Create a new authorization wrapper.
163 const fn new(token: Box<str>) -> Self {
164 Self { inner: token }
165 }
166}
167
168impl Debug for Token {
169 fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
170 f.write_str("<redacted>")
171 }
172}
173
174impl Deref for Token {
175 type Target = str;
176
177 fn deref(&self) -> &Self::Target {
178 &self.inner
179 }
180}
181
182/// Twilight's http client.
183///
184/// Almost all of the client methods require authentication, and as such, the client must be
185/// supplied with a Discord Token. Get yours [here].
186///
187/// # Interactions
188///
189/// HTTP interaction requests may be accessed via the [`Client::interaction`]
190/// method.
191///
192/// # OAuth2
193///
194/// To use Bearer tokens prefix the token with `"Bearer "`, including the space
195/// at the end like so:
196///
197/// ```no_run
198/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
199/// use std::env;
200/// use twilight_http::Client;
201///
202/// let bearer = env::var("BEARER_TOKEN")?;
203/// let token = format!("Bearer {bearer}");
204///
205/// let client = Client::new(token);
206/// # Ok(()) }
207/// ```
208///
209/// # Using the client in multiple tasks
210///
211/// To use a client instance in multiple tasks, consider wrapping it in an
212/// [`std::sync::Arc`] or [`std::rc::Rc`].
213///
214/// # Unauthorized behavior
215///
216/// When the client encounters an Unauthorized response it will take note that
217/// the configured token is invalid. This may occur when the token has been
218/// revoked or expired. When this happens, you must create a new client with the
219/// new token. The client will no longer execute requests in order to
220/// prevent API bans and will always return [`ErrorType::Unauthorized`].
221///
222/// # Examples
223///
224/// Create a client called `client`:
225/// ```no_run
226/// use twilight_http::Client;
227///
228/// # #[tokio::main]
229/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
230/// let client = Client::new("my token".to_owned());
231/// # Ok(()) }
232/// ```
233///
234/// Use [`ClientBuilder`] to create a client called `client`, with a shorter
235/// timeout:
236/// ```no_run
237/// use std::time::Duration;
238/// use twilight_http::Client;
239///
240/// # #[tokio::main]
241/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
242/// let client = Client::builder()
243/// .token("my token".to_owned())
244/// .timeout(Duration::from_secs(5))
245/// .build();
246/// # Ok(()) }
247/// ```
248///
249/// All the examples on this page assume you have already created a client, and have named it
250/// `client`.
251///
252/// [here]: https://discord.com/developers/applications
253#[derive(Debug)]
254pub struct Client {
255 pub(crate) default_allowed_mentions: Option<AllowedMentions>,
256 default_headers: Option<HeaderMap>,
257 http: HyperClient<Connector, Full<Bytes>>,
258 proxy: Option<Box<str>>,
259 ratelimiter: Option<RateLimiter>,
260 timeout: Duration,
261 /// Whether the token is invalidated.
262 ///
263 /// Whether an invalid token is tracked can be configured via
264 /// [`ClientBuilder::remember_invalid_token`].
265 token_invalidated: Option<Arc<AtomicBool>>,
266 token: Option<Token>,
267 use_http: bool,
268}
269
270impl Client {
271 /// Create a new client with a token.
272 pub fn new(token: String) -> Self {
273 ClientBuilder::default().token(token).build()
274 }
275
276 /// Create a new builder to create a client.
277 ///
278 /// Refer to its documentation for more information.
279 pub fn builder() -> ClientBuilder {
280 ClientBuilder::new()
281 }
282
283 /// Retrieve an immutable reference to the token used by the client.
284 ///
285 /// If the initial token provided is not prefixed with `Bot `, it will be, and this method
286 /// reflects that.
287 pub fn token(&self) -> Option<&str> {
288 self.token.as_deref()
289 }
290
291 /// Create an interface for using interactions.
292 ///
293 /// An application ID is required to be passed in to use interactions. The
294 /// ID may be retrieved via [`current_user_application`] and cached for use
295 /// with this method.
296 ///
297 /// # Examples
298 ///
299 /// Retrieve the application ID and then use an interaction request:
300 ///
301 /// ```no_run
302 /// # #[tokio::main]
303 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
304 /// use std::env;
305 /// use twilight_http::Client;
306 ///
307 /// let client = Client::new(env::var("DISCORD_TOKEN")?);
308 ///
309 /// // Cache the application ID for repeated use later in the process.
310 /// let application_id = {
311 /// let response = client.current_user_application().await?;
312 ///
313 /// response.model().await?.id
314 /// };
315 ///
316 /// // Later in the process...
317 /// let commands = client
318 /// .interaction(application_id)
319 /// .global_commands()
320 /// .await?
321 /// .models()
322 /// .await?;
323 ///
324 /// println!("there are {} global commands", commands.len());
325 /// # Ok(()) }
326 /// ```
327 ///
328 /// [`current_user_application`]: Self::current_user_application
329 pub const fn interaction(
330 &self,
331 application_id: Id<ApplicationMarker>,
332 ) -> InteractionClient<'_> {
333 InteractionClient::new(self, application_id)
334 }
335
336 /// Get an immutable reference to the default [`AllowedMentions`] for sent
337 /// messages.
338 pub const fn default_allowed_mentions(&self) -> Option<&AllowedMentions> {
339 self.default_allowed_mentions.as_ref()
340 }
341
342 /// Get the Ratelimiter used by the client internally.
343 ///
344 /// This will return `None` only if ratelimit handling
345 /// has been explicitly disabled in the [`ClientBuilder`].
346 pub const fn ratelimiter(&self) -> Option<&RateLimiter> {
347 self.ratelimiter.as_ref()
348 }
349
350 /// Get an auto moderation rule in a guild.
351 ///
352 /// Requires the [`MANAGE_GUILD`] permission.
353 ///
354 /// [`MANAGE_GUILD`]: twilight_model::guild::Permissions::MANAGE_GUILD
355 pub const fn auto_moderation_rule(
356 &self,
357 guild_id: Id<GuildMarker>,
358 auto_moderation_rule_id: Id<AutoModerationRuleMarker>,
359 ) -> GetAutoModerationRule<'_> {
360 GetAutoModerationRule::new(self, guild_id, auto_moderation_rule_id)
361 }
362
363 /// Get the auto moderation rules in a guild.
364 ///
365 /// Requires the [`MANAGE_GUILD`] permission.
366 ///
367 /// [`MANAGE_GUILD`]: twilight_model::guild::Permissions::MANAGE_GUILD
368 pub const fn auto_moderation_rules(
369 &self,
370 guild_id: Id<GuildMarker>,
371 ) -> GetGuildAutoModerationRules<'_> {
372 GetGuildAutoModerationRules::new(self, guild_id)
373 }
374
375 /// Create an auto moderation rule within a guild.
376 ///
377 /// Requires the [`MANAGE_GUILD`] permission.
378 ///
379 /// # Examples
380 ///
381 /// Create a rule that deletes messages that contain the word "darn":
382 ///
383 /// ```no_run
384 /// # #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> {
385 /// use twilight_http::Client;
386 /// use twilight_model::{guild::auto_moderation::AutoModerationEventType, id::Id};
387 ///
388 /// let client = Client::new("my token".to_owned());
389 ///
390 /// let guild_id = Id::new(1);
391 /// client
392 /// .create_auto_moderation_rule(guild_id, "no darns", AutoModerationEventType::MessageSend)
393 /// .action_block_message()
394 /// .enabled(true)
395 /// .with_keyword(&["darn"], &["d(?:4|a)rn"], &["darn it"])
396 /// .await?;
397 /// # Ok(()) }
398 /// ```
399 ///
400 /// [`MANAGE_GUILD`]: twilight_model::guild::Permissions::MANAGE_GUILD
401 pub const fn create_auto_moderation_rule<'a>(
402 &'a self,
403 guild_id: Id<GuildMarker>,
404 name: &'a str,
405 event_type: AutoModerationEventType,
406 ) -> CreateAutoModerationRule<'a> {
407 CreateAutoModerationRule::new(self, guild_id, name, event_type)
408 }
409
410 /// Delete an auto moderation rule in a guild.
411 ///
412 /// Requires the [`MANAGE_GUILD`] permission.
413 ///
414 /// [`MANAGE_GUILD`]: twilight_model::guild::Permissions::MANAGE_GUILD
415 pub const fn delete_auto_moderation_rule(
416 &self,
417 guild_id: Id<GuildMarker>,
418 auto_moderation_rule_id: Id<AutoModerationRuleMarker>,
419 ) -> DeleteAutoModerationRule<'_> {
420 DeleteAutoModerationRule::new(self, guild_id, auto_moderation_rule_id)
421 }
422
423 /// Update an auto moderation rule in a guild.
424 ///
425 /// Requires the [`MANAGE_GUILD`] permission.
426 ///
427 /// [`MANAGE_GUILD`]: twilight_model::guild::Permissions::MANAGE_GUILD
428 pub const fn update_auto_moderation_rule(
429 &self,
430 guild_id: Id<GuildMarker>,
431 auto_moderation_rule_id: Id<AutoModerationRuleMarker>,
432 ) -> UpdateAutoModerationRule<'_> {
433 UpdateAutoModerationRule::new(self, guild_id, auto_moderation_rule_id)
434 }
435
436 /// Get the audit log for a guild.
437 ///
438 /// # Examples
439 ///
440 /// ```no_run
441 /// # use twilight_http::Client;
442 /// use twilight_model::id::Id;
443 ///
444 /// # #[tokio::main]
445 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
446 /// # let client = Client::new("token".to_owned());
447 /// let guild_id = Id::new(101);
448 /// let audit_log = client.audit_log(guild_id).await?;
449 /// # Ok(()) }
450 /// ```
451 pub const fn audit_log(&self, guild_id: Id<GuildMarker>) -> GetAuditLog<'_> {
452 GetAuditLog::new(self, guild_id)
453 }
454
455 /// Retrieve the bans for a guild.
456 ///
457 /// # Examples
458 ///
459 /// Retrieve the bans for guild `1`:
460 ///
461 /// ```no_run
462 /// # use twilight_http::Client;
463 /// use twilight_model::id::Id;
464 /// #
465 /// # #[tokio::main]
466 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
467 /// # let client = Client::new("my token".to_owned());
468 /// #
469 /// let guild_id = Id::new(1);
470 ///
471 /// let bans = client.bans(guild_id).await?;
472 /// # Ok(()) }
473 /// ```
474 pub const fn bans(&self, guild_id: Id<GuildMarker>) -> GetBans<'_> {
475 GetBans::new(self, guild_id)
476 }
477
478 /// Get information about a ban of a guild.
479 ///
480 /// Includes the user banned and the reason.
481 pub const fn ban(&self, guild_id: Id<GuildMarker>, user_id: Id<UserMarker>) -> GetBan<'_> {
482 GetBan::new(self, guild_id, user_id)
483 }
484
485 /// Bans a user from a guild, optionally with the number of seconds' worth of
486 /// messages to delete and the reason.
487 ///
488 /// # Examples
489 ///
490 /// Ban user `200` from guild `100`, deleting
491 /// `86_400` second's (this is equivalent to `1` day) worth of messages, for the reason `"memes"`:
492 ///
493 /// ```no_run
494 /// # use twilight_http::{request::AuditLogReason, Client};
495 /// use twilight_model::id::Id;
496 /// #
497 /// # #[tokio::main]
498 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
499 /// # let client = Client::new("my token".to_owned());
500 /// #
501 /// let guild_id = Id::new(100);
502 /// let user_id = Id::new(200);
503 /// client
504 /// .create_ban(guild_id, user_id)
505 /// .delete_message_seconds(86_400)
506 /// .reason("memes")
507 /// .await?;
508 /// # Ok(()) }
509 /// ```
510 pub const fn create_ban(
511 &self,
512 guild_id: Id<GuildMarker>,
513 user_id: Id<UserMarker>,
514 ) -> CreateBan<'_> {
515 CreateBan::new(self, guild_id, user_id)
516 }
517
518 /// Remove a ban from a user in a guild.
519 ///
520 /// # Examples
521 ///
522 /// Unban user `200` from guild `100`:
523 ///
524 /// ```no_run
525 /// # use twilight_http::Client;
526 /// use twilight_model::id::Id;
527 /// #
528 /// # #[tokio::main]
529 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
530 /// # let client = Client::new("my token".to_owned());
531 /// #
532 /// let guild_id = Id::new(100);
533 /// let user_id = Id::new(200);
534 ///
535 /// client.delete_ban(guild_id, user_id).await?;
536 /// # Ok(()) }
537 /// ```
538 pub const fn delete_ban(
539 &self,
540 guild_id: Id<GuildMarker>,
541 user_id: Id<UserMarker>,
542 ) -> DeleteBan<'_> {
543 DeleteBan::new(self, guild_id, user_id)
544 }
545
546 /// Perform a bulk ban of users from a guild.
547 ///
548 /// Requires both the [`BAN_MEMBERS`] and [`MANAGE_GUILD`] permissions.
549 ///
550 /// # Examples
551 ///
552 /// Ban a list of users from a guild along with the last day's messages:
553 ///
554 /// ```no_run
555 /// use twilight_http::{Client, request::AuditLogReason};
556 /// use twilight_model::id::Id;
557 ///
558 /// # #[tokio::main]
559 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
560 /// # use twilight_model::id::marker::UserMarker;
561 /// # fn determine_users_to_ban() -> Vec<Id<UserMarker>> { Vec::new() }
562 /// let client = Client::new("my token".to_owned());
563 ///
564 /// let guild_id = Id::new(1);
565 /// let user_ids = determine_users_to_ban();
566 ///
567 /// client
568 /// .bulk_guild_ban(guild_id, &user_ids)
569 /// .delete_message_seconds(86_400)
570 /// .reason("insulting my little pony")
571 /// .await?;
572 /// # Ok(()) }
573 /// ```
574 ///
575 /// [`BAN_MEMBERS`]: twilight_model::guild::Permissions::BAN_MEMBERS
576 /// [`MANAGE_GUILD`]: twilight_model::guild::Permissions::MANAGE_GUILD
577 pub fn bulk_guild_ban<'a>(
578 &'a self,
579 guild_id: Id<GuildMarker>,
580 user_ids: &'a [Id<UserMarker>],
581 ) -> BulkGuildBan<'a> {
582 BulkGuildBan::new(self, guild_id, user_ids)
583 }
584
585 /// Get a channel by its ID.
586 ///
587 /// # Examples
588 ///
589 /// Get channel `100`:
590 ///
591 /// ```no_run
592 /// # use twilight_http::Client;
593 /// # use twilight_model::id::Id;
594 /// #
595 /// # #[tokio::main]
596 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
597 /// # let client = Client::new("my token".to_owned());
598 /// #
599 /// let channel_id = Id::new(100);
600 /// #
601 /// let channel = client.channel(channel_id).await?;
602 /// # Ok(()) }
603 /// ```
604 pub const fn channel(&self, channel_id: Id<ChannelMarker>) -> GetChannel<'_> {
605 GetChannel::new(self, channel_id)
606 }
607
608 /// Delete a channel by ID.
609 pub const fn delete_channel(&self, channel_id: Id<ChannelMarker>) -> DeleteChannel<'_> {
610 DeleteChannel::new(self, channel_id)
611 }
612
613 /// Update a channel.
614 pub const fn update_channel(&self, channel_id: Id<ChannelMarker>) -> UpdateChannel<'_> {
615 UpdateChannel::new(self, channel_id)
616 }
617
618 /// Follows a news channel by [`Id<ChannelMarker>`].
619 ///
620 /// The type returned is [`FollowedChannel`].
621 ///
622 /// [`FollowedChannel`]: ::twilight_model::channel::FollowedChannel
623 pub const fn follow_news_channel(
624 &self,
625 channel_id: Id<ChannelMarker>,
626 webhook_channel_id: Id<ChannelMarker>,
627 ) -> FollowNewsChannel<'_> {
628 FollowNewsChannel::new(self, channel_id, webhook_channel_id)
629 }
630
631 /// Get the invites for a guild channel.
632 ///
633 /// Requires the [`MANAGE_CHANNELS`] permission. This method only works if
634 /// the channel is a guild channel.
635 ///
636 /// [`MANAGE_CHANNELS`]: twilight_model::guild::Permissions::MANAGE_CHANNELS
637 pub const fn channel_invites(&self, channel_id: Id<ChannelMarker>) -> GetChannelInvites<'_> {
638 GetChannelInvites::new(self, channel_id)
639 }
640
641 /// Get channel messages, by [`Id<ChannelMarker>`].
642 ///
643 /// Only one of [`after`], [`around`], and [`before`] can be specified at a time.
644 /// Once these are specified, the type returned is [`GetChannelMessagesConfigured`].
645 ///
646 /// If [`limit`] is unspecified, the default set by Discord is 50.
647 ///
648 /// # Examples
649 ///
650 /// ```no_run
651 /// use twilight_http::Client;
652 /// use twilight_model::id::Id;
653 ///
654 /// # #[tokio::main]
655 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
656 /// let client = Client::new("my token".to_owned());
657 /// let channel_id = Id::new(123);
658 /// let message_id = Id::new(234);
659 /// let limit: u16 = 6;
660 ///
661 /// let messages = client
662 /// .channel_messages(channel_id)
663 /// .before(message_id)
664 /// .limit(limit)
665 /// .await?;
666 ///
667 /// # Ok(()) }
668 /// ```
669 ///
670 /// # Errors
671 ///
672 /// Returns an error of type [`ValidationErrorType::GetChannelMessages`] if
673 /// the amount is less than 1 or greater than 100.
674 ///
675 /// [`GetChannelMessagesConfigured`]: crate::request::channel::message::GetChannelMessagesConfigured
676 /// [`ValidationErrorType::GetChannelMessages`]: twilight_validate::request::ValidationErrorType::GetChannelMessages
677 /// [`after`]: GetChannelMessages::after
678 /// [`around`]: GetChannelMessages::around
679 /// [`before`]: GetChannelMessages::before
680 /// [`limit`]: GetChannelMessages::limit
681 pub const fn channel_messages(&self, channel_id: Id<ChannelMarker>) -> GetChannelMessages<'_> {
682 GetChannelMessages::new(self, channel_id)
683 }
684
685 /// Search a guild's messages.
686 ///
687 /// Returned messages do not have the `reactions` field.
688 ///
689 /// Requires the [`READ_MESSAGE_HISTORY`] permission. This endpoint is
690 /// restricted according to whether the [`MESSAGE_CONTENT` Privileged Intent]
691 /// is enabled for your application.
692 ///
693 /// [`READ_MESSAGE_HISTORY`]: twilight_model::guild::Permissions::READ_MESSAGE_HISTORY
694 /// [`MESSAGE_CONTENT` Privileged Intent]: twilight_model::gateway::Intents::MESSAGE_CONTENT
695 pub const fn search_guild_messages(
696 &self,
697 guild_id: Id<GuildMarker>,
698 ) -> SearchGuildMessages<'_> {
699 SearchGuildMessages::new(self, guild_id)
700 }
701
702 pub const fn delete_channel_permission(
703 &self,
704 channel_id: Id<ChannelMarker>,
705 ) -> DeleteChannelPermission<'_> {
706 DeleteChannelPermission::new(self, channel_id)
707 }
708
709 /// Update the permissions for a role or a user in a channel.
710 ///
711 /// # Examples:
712 ///
713 /// Create permission overrides for a role to view the channel, but not send
714 /// messages:
715 ///
716 /// ```no_run
717 /// # #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> {
718 /// # use twilight_http::Client;
719 /// # let client = Client::new("my token".to_owned());
720 /// #
721 /// use twilight_model::{
722 /// guild::Permissions,
723 /// http::permission_overwrite::{PermissionOverwrite, PermissionOverwriteType},
724 /// id::{Id, marker::RoleMarker},
725 /// };
726 ///
727 /// let channel_id = Id::new(123);
728 /// let role_id: Id<RoleMarker> = Id::new(432);
729 /// let permission_overwrite = PermissionOverwrite {
730 /// allow: Some(Permissions::VIEW_CHANNEL),
731 /// deny: Some(Permissions::SEND_MESSAGES),
732 /// id: role_id.cast(),
733 /// kind: PermissionOverwriteType::Role,
734 /// };
735 ///
736 /// client
737 /// .update_channel_permission(channel_id, &permission_overwrite)
738 /// .await?;
739 /// # Ok(()) }
740 /// ```
741 pub const fn update_channel_permission(
742 &self,
743 channel_id: Id<ChannelMarker>,
744 permission_overwrite: &PermissionOverwrite,
745 ) -> UpdateChannelPermission<'_> {
746 UpdateChannelPermission::new(self, channel_id, permission_overwrite)
747 }
748
749 /// Get a member's computed permissions in a channel.
750 pub const fn channel_member_permissions(
751 &self,
752 channel_id: Id<ChannelMarker>,
753 user_id: Id<UserMarker>,
754 ) -> GetChannelMemberPermissions<'_> {
755 GetChannelMemberPermissions::new(self, channel_id, user_id)
756 }
757
758 /// Get the permissions granted by the specified role together with `@everyone`,
759 /// applying their channel overwrites.
760 pub const fn channel_role_permissions(
761 &self,
762 channel_id: Id<ChannelMarker>,
763 role_id: Id<RoleMarker>,
764 ) -> GetChannelRolePermissions<'_> {
765 GetChannelRolePermissions::new(self, channel_id, role_id)
766 }
767
768 /// Get all the webhooks of a channel.
769 pub const fn channel_webhooks(&self, channel_id: Id<ChannelMarker>) -> GetChannelWebhooks<'_> {
770 GetChannelWebhooks::new(self, channel_id)
771 }
772
773 /// Get information about the current user.
774 pub const fn current_user(&self) -> GetCurrentUser<'_> {
775 GetCurrentUser::new(self)
776 }
777
778 /// Get information about the current user in a guild.
779 pub const fn current_user_guild_member(
780 &self,
781 guild_id: Id<GuildMarker>,
782 ) -> GetCurrentUserGuildMember<'_> {
783 GetCurrentUserGuildMember::new(self, guild_id)
784 }
785
786 /// Get information about the current OAuth2 authorization.
787 pub const fn current_authorization(&self) -> GetCurrentAuthorizationInformation<'_> {
788 GetCurrentAuthorizationInformation::new(self)
789 }
790
791 /// Get information about the current bot application.
792 pub const fn current_user_application(&self) -> GetUserApplicationInfo<'_> {
793 GetUserApplicationInfo::new(self)
794 }
795
796 /// Update the current user's application.
797 pub const fn update_current_user_application(&self) -> UpdateCurrentUserApplication<'_> {
798 UpdateCurrentUserApplication::new(self)
799 }
800
801 /// Update the current user.
802 ///
803 /// All parameters are optional. If the username is changed, it may cause the discriminator to
804 /// be randomized.
805 pub const fn update_current_user(&self) -> UpdateCurrentUser<'_> {
806 UpdateCurrentUser::new(self)
807 }
808
809 /// Get voice state of the current user in a guild.
810 ///
811 /// # Caveats
812 ///
813 /// - Current user must already have joined a voice/stage channel in this guild.
814 pub const fn current_user_voice_state(
815 &self,
816 guild_id: Id<GuildMarker>,
817 ) -> GetCurrentUserVoiceState<'_> {
818 GetCurrentUserVoiceState::new(self, guild_id)
819 }
820
821 /// Update the current user's voice state.
822 ///
823 /// All parameters are optional.
824 ///
825 /// # Caveats
826 ///
827 /// - `channel_id` must currently point to a stage channel.
828 /// - Current user must have already joined `channel_id`.
829 pub const fn update_current_user_voice_state(
830 &self,
831 guild_id: Id<GuildMarker>,
832 ) -> UpdateCurrentUserVoiceState<'_> {
833 UpdateCurrentUserVoiceState::new(self, guild_id)
834 }
835
836 /// Get the current user's connections.
837 ///
838 /// Requires the `connections` `OAuth2` scope.
839 pub const fn current_user_connections(&self) -> GetCurrentUserConnections<'_> {
840 GetCurrentUserConnections::new(self)
841 }
842
843 /// Returns a list of guilds for the current user.
844 ///
845 /// # Examples
846 ///
847 /// Get the first 25 guilds with an ID after `300` and before
848 /// `400`:
849 ///
850 /// ```no_run
851 /// # use twilight_http::Client;
852 /// use twilight_model::id::Id;
853 ///
854 /// # #[tokio::main]
855 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
856 /// # let client = Client::new("my token".to_owned());
857 /// #
858 /// let after = Id::new(300);
859 /// let before = Id::new(400);
860 /// let guilds = client
861 /// .current_user_guilds()
862 /// .after(after)
863 /// .before(before)
864 /// .limit(25)
865 /// .await?;
866 /// # Ok(()) }
867 /// ```
868 pub const fn current_user_guilds(&self) -> GetCurrentUserGuilds<'_> {
869 GetCurrentUserGuilds::new(self)
870 }
871
872 /// Get the emojis for a guild, by the guild's id.
873 ///
874 /// # Examples
875 ///
876 /// Get the emojis for guild `100`:
877 ///
878 /// ```no_run
879 /// # use twilight_http::Client;
880 /// # use twilight_model::id::Id;
881 /// #
882 /// # #[tokio::main]
883 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
884 /// # let client = Client::new("my token".to_owned());
885 /// #
886 /// let guild_id = Id::new(100);
887 ///
888 /// client.emojis(guild_id).await?;
889 /// # Ok(()) }
890 /// ```
891 pub const fn emojis(&self, guild_id: Id<GuildMarker>) -> GetEmojis<'_> {
892 GetEmojis::new(self, guild_id)
893 }
894
895 /// Get the entitlements for an application.
896 ///
897 /// # Examples
898 ///
899 /// Get entitlements for the application `100`:
900 ///
901 /// ```no_run
902 /// # use twilight_http::Client;
903 /// # use twilight_model::id::Id;
904 ///
905 /// # #[tokio::main]
906 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
907 /// # let client = Client::new("my token".to_owned());
908 /// #
909 /// let application_id = Id::new(100);
910 ///
911 /// client.entitlements(application_id).await?;
912 /// # Ok(()) }
913 /// ```
914 pub const fn entitlements(&self, application_id: Id<ApplicationMarker>) -> GetEntitlements<'_> {
915 GetEntitlements::new(self, application_id)
916 }
917
918 /// Get an entitlement.
919 pub const fn entitlement(
920 &self,
921 application_id: Id<ApplicationMarker>,
922 entitlement_id: Id<EntitlementMarker>,
923 ) -> GetEntitlement<'_> {
924 GetEntitlement::new(self, application_id, entitlement_id)
925 }
926
927 /// Get an emoji for a guild by the the guild's ID and emoji's ID.
928 ///
929 /// # Examples
930 ///
931 /// Get emoji `100` from guild `50`:
932 ///
933 /// ```no_run
934 /// # use twilight_http::Client;
935 /// # use twilight_model::id::Id;
936 /// #
937 /// # #[tokio::main]
938 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
939 /// # let client = Client::new("my token".to_owned());
940 /// #
941 /// let guild_id = Id::new(50);
942 /// let emoji_id = Id::new(100);
943 ///
944 /// client.emoji(guild_id, emoji_id).await?;
945 /// # Ok(()) }
946 /// ```
947 pub const fn emoji(
948 &self,
949 guild_id: Id<GuildMarker>,
950 emoji_id: Id<EmojiMarker>,
951 ) -> GetEmoji<'_> {
952 GetEmoji::new(self, guild_id, emoji_id)
953 }
954
955 /// Create an emoji in a guild.
956 ///
957 /// The emoji must be a Data URI, in the form of
958 /// `data:image/{type};base64,{data}` where `{type}` is the image MIME type
959 /// and `{data}` is the base64-encoded image. See [Discord Docs/Image Data].
960 ///
961 /// [Discord Docs/Image Data]: https://discord.com/developers/docs/reference#image-data
962 pub const fn create_emoji<'a>(
963 &'a self,
964 guild_id: Id<GuildMarker>,
965 name: &'a str,
966 image: &'a str,
967 ) -> CreateEmoji<'a> {
968 CreateEmoji::new(self, guild_id, name, image)
969 }
970
971 /// Delete an emoji in a guild, by id.
972 pub const fn delete_emoji(
973 &self,
974 guild_id: Id<GuildMarker>,
975 emoji_id: Id<EmojiMarker>,
976 ) -> DeleteEmoji<'_> {
977 DeleteEmoji::new(self, guild_id, emoji_id)
978 }
979
980 /// Update an emoji in a guild, by id.
981 pub const fn update_emoji(
982 &self,
983 guild_id: Id<GuildMarker>,
984 emoji_id: Id<EmojiMarker>,
985 ) -> UpdateEmoji<'_> {
986 UpdateEmoji::new(self, guild_id, emoji_id)
987 }
988
989 /// Get information about the gateway, optionally with additional information detailing the
990 /// number of shards to use and sessions remaining.
991 ///
992 /// # Examples
993 ///
994 /// Get the gateway connection URL without bot information:
995 ///
996 /// ```no_run
997 /// # use twilight_http::Client;
998 /// #
999 /// # #[tokio::main]
1000 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
1001 /// # let client = Client::new("my token".to_owned());
1002 /// #
1003 /// let info = client.gateway().await?;
1004 /// # Ok(()) }
1005 /// ```
1006 ///
1007 /// Get the gateway connection URL with additional shard and session information, which
1008 /// requires specifying a bot token:
1009 ///
1010 /// ```no_run
1011 /// # use twilight_http::Client;
1012 /// #
1013 /// # #[tokio::main]
1014 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
1015 /// # let client = Client::new("my token".to_owned());
1016 /// #
1017 /// let info = client.gateway().authed().await?.model().await?;
1018 ///
1019 /// println!("URL: {}", info.url);
1020 /// println!("Recommended shards to use: {}", info.shards);
1021 /// # Ok(()) }
1022 /// ```
1023 pub const fn gateway(&self) -> GetGateway<'_> {
1024 GetGateway::new(self)
1025 }
1026
1027 /// Get information about a guild.
1028 pub const fn guild(&self, guild_id: Id<GuildMarker>) -> GetGuild<'_> {
1029 GetGuild::new(self, guild_id)
1030 }
1031
1032 /// Delete a guild permanently. The user must be the owner.
1033 pub const fn delete_guild(&self, guild_id: Id<GuildMarker>) -> DeleteGuild<'_> {
1034 DeleteGuild::new(self, guild_id)
1035 }
1036
1037 /// Update a guild.
1038 ///
1039 /// All endpoints are optional. See [Discord Docs/Modify Guild].
1040 ///
1041 /// [Discord Docs/Modify Guild]: https://discord.com/developers/docs/resources/guild#modify-guild
1042 pub const fn update_guild(&self, guild_id: Id<GuildMarker>) -> UpdateGuild<'_> {
1043 UpdateGuild::new(self, guild_id)
1044 }
1045
1046 /// Leave a guild by id.
1047 pub const fn leave_guild(&self, guild_id: Id<GuildMarker>) -> LeaveGuild<'_> {
1048 LeaveGuild::new(self, guild_id)
1049 }
1050
1051 /// Get the channels in a guild.
1052 pub const fn guild_channels(&self, guild_id: Id<GuildMarker>) -> GetGuildChannels<'_> {
1053 GetGuildChannels::new(self, guild_id)
1054 }
1055
1056 /// Create a new request to create a guild channel.
1057 ///
1058 /// All fields are optional except for name. The minimum length of the name
1059 /// is 1 UTF-16 character and the maximum is 100 UTF-16 characters.
1060 ///
1061 /// # Errors
1062 ///
1063 /// Returns an error of type [`NameInvalid`] when the length of the name is
1064 /// either fewer than 1 UTF-16 character or more than 100 UTF-16 characters.
1065 ///
1066 /// Returns an error of type [`RateLimitPerUserInvalid`] when the seconds of
1067 /// the rate limit per user is more than 21600.
1068 ///
1069 /// Returns an error of type [`TopicInvalid`] when the length of the topic
1070 /// is more than 1024 UTF-16 characters.
1071 ///
1072 /// [`NameInvalid`]: twilight_validate::channel::ChannelValidationErrorType::NameInvalid
1073 /// [`RateLimitPerUserInvalid`]: twilight_validate::channel::ChannelValidationErrorType::RateLimitPerUserInvalid
1074 /// [`TopicInvalid`]: twilight_validate::channel::ChannelValidationErrorType::TopicInvalid
1075 pub fn create_guild_channel<'a>(
1076 &'a self,
1077 guild_id: Id<GuildMarker>,
1078 name: &'a str,
1079 ) -> CreateGuildChannel<'a> {
1080 CreateGuildChannel::new(self, guild_id, name)
1081 }
1082
1083 /// Modify the guild onboarding flow.
1084 pub const fn update_guild_onboarding(
1085 &self,
1086 guild_id: Id<GuildMarker>,
1087 fields: UpdateGuildOnboardingFields,
1088 ) -> UpdateGuildOnboarding<'_> {
1089 UpdateGuildOnboarding::new(self, guild_id, fields)
1090 }
1091
1092 /// Modify the positions of the channels.
1093 ///
1094 /// The minimum amount of channels to modify, is a swap between two channels.
1095 pub const fn update_guild_channel_positions<'a>(
1096 &'a self,
1097 guild_id: Id<GuildMarker>,
1098 channel_positions: &'a [Position],
1099 ) -> UpdateGuildChannelPositions<'a> {
1100 UpdateGuildChannelPositions::new(self, guild_id, channel_positions)
1101 }
1102
1103 /// Get a guild's widget.
1104 ///
1105 /// See [Discord Docs/Get Guild Widget].
1106 ///
1107 /// [Discord Docs/Get Guild Widget]: https://discord.com/developers/docs/resources/guild#get-guild-widget
1108 pub const fn guild_widget(&self, guild_id: Id<GuildMarker>) -> GetGuildWidget<'_> {
1109 GetGuildWidget::new(self, guild_id)
1110 }
1111
1112 /// Get a guild's widget settings.
1113 ///
1114 /// See [Discord Docs/Get Guild Widget Settings].
1115 ///
1116 /// [Discord Docs/Get Guild Widget]: https://discord.com/developers/docs/resources/guild#get-guild-widget-settings
1117 pub const fn guild_widget_settings(
1118 &self,
1119 guild_id: Id<GuildMarker>,
1120 ) -> GetGuildWidgetSettings<'_> {
1121 GetGuildWidgetSettings::new(self, guild_id)
1122 }
1123
1124 /// Modify a guild's widget.
1125 ///
1126 /// See [Discord Docs/Modify Guild Widget].
1127 ///
1128 /// [Discord Docs/Modify Guild Widget]: https://discord.com/developers/docs/resources/guild#modify-guild-widget
1129 pub const fn update_guild_widget_settings(
1130 &self,
1131 guild_id: Id<GuildMarker>,
1132 ) -> UpdateGuildWidgetSettings<'_> {
1133 UpdateGuildWidgetSettings::new(self, guild_id)
1134 }
1135
1136 /// Get the guild's integrations.
1137 pub const fn guild_integrations(&self, guild_id: Id<GuildMarker>) -> GetGuildIntegrations<'_> {
1138 GetGuildIntegrations::new(self, guild_id)
1139 }
1140
1141 /// Delete an integration for a guild, by the integration's id.
1142 pub const fn delete_guild_integration(
1143 &self,
1144 guild_id: Id<GuildMarker>,
1145 integration_id: Id<IntegrationMarker>,
1146 ) -> DeleteGuildIntegration<'_> {
1147 DeleteGuildIntegration::new(self, guild_id, integration_id)
1148 }
1149
1150 /// Get information about the invites of a guild.
1151 ///
1152 /// Requires the [`MANAGE_GUILD`] permission.
1153 ///
1154 /// [`MANAGE_GUILD`]: twilight_model::guild::Permissions::MANAGE_GUILD
1155 pub const fn guild_invites(&self, guild_id: Id<GuildMarker>) -> GetGuildInvites<'_> {
1156 GetGuildInvites::new(self, guild_id)
1157 }
1158
1159 /// Update a guild's MFA level.
1160 pub const fn update_guild_mfa(
1161 &self,
1162 guild_id: Id<GuildMarker>,
1163 level: MfaLevel,
1164 ) -> UpdateGuildMfa<'_> {
1165 UpdateGuildMfa::new(self, guild_id, level)
1166 }
1167
1168 /// Get the members of a guild, by id.
1169 ///
1170 /// The upper limit to this request is 1000. If more than 1000 members are needed, the requests
1171 /// must be chained. Discord defaults the limit to 1.
1172 ///
1173 /// # Examples
1174 ///
1175 /// Get the first 500 members of guild `100` after user ID `3000`:
1176 ///
1177 /// ```no_run
1178 /// # use twilight_http::Client;
1179 /// use twilight_model::id::Id;
1180 /// #
1181 /// # #[tokio::main]
1182 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
1183 /// # let client = Client::new("my token".to_owned());
1184 /// #
1185 /// let guild_id = Id::new(100);
1186 /// let user_id = Id::new(3000);
1187 /// let members = client
1188 /// .guild_members(guild_id)
1189 /// .after(user_id)
1190 /// .limit(500)
1191 /// .await?;
1192 /// # Ok(()) }
1193 /// ```
1194 ///
1195 /// # Errors
1196 ///
1197 /// Returns an error of type [`ValidationErrorType::GetGuildMembers`] if the
1198 /// limit is invalid.
1199 ///
1200 /// [`ValidationErrorType::GetGuildMembers`]: twilight_validate::request::ValidationErrorType::GetGuildMembers
1201 pub const fn guild_members(&self, guild_id: Id<GuildMarker>) -> GetGuildMembers<'_> {
1202 GetGuildMembers::new(self, guild_id)
1203 }
1204
1205 /// Search the members of a specific guild by a query.
1206 ///
1207 /// The upper limit to this request is 1000. Discord defaults the limit to 1.
1208 ///
1209 /// # Examples
1210 ///
1211 /// Get the first 10 members of guild `100` matching `Wumpus`:
1212 ///
1213 /// ```no_run
1214 /// use twilight_http::Client;
1215 /// use twilight_model::id::Id;
1216 ///
1217 /// # #[tokio::main]
1218 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
1219 /// let client = Client::new("my token".to_owned());
1220 ///
1221 /// let guild_id = Id::new(100);
1222 /// let members = client
1223 /// .search_guild_members(guild_id, "Wumpus")
1224 /// .limit(10)
1225 /// .await?;
1226 /// # Ok(()) }
1227 /// ```
1228 ///
1229 /// # Errors
1230 ///
1231 /// Returns an error of type [`ValidationErrorType::SearchGuildMembers`] if
1232 /// the limit is invalid.
1233 ///
1234 /// [`GUILD_MEMBERS`]: twilight_model::gateway::Intents::GUILD_MEMBERS
1235 /// [`ValidationErrorType::SearchGuildMembers`]: twilight_validate::request::ValidationErrorType::SearchGuildMembers
1236 pub const fn search_guild_members<'a>(
1237 &'a self,
1238 guild_id: Id<GuildMarker>,
1239 query: &'a str,
1240 ) -> SearchGuildMembers<'a> {
1241 SearchGuildMembers::new(self, guild_id, query)
1242 }
1243
1244 /// Get a member of a guild, by their id.
1245 pub const fn guild_member(
1246 &self,
1247 guild_id: Id<GuildMarker>,
1248 user_id: Id<UserMarker>,
1249 ) -> GetMember<'_> {
1250 GetMember::new(self, guild_id, user_id)
1251 }
1252
1253 /// Get a member's computed guild permissions, combining their roles with
1254 /// `@everyone`.
1255 pub const fn guild_member_permissions(
1256 &self,
1257 guild_id: Id<GuildMarker>,
1258 user_id: Id<UserMarker>,
1259 ) -> GetGuildMemberPermissions<'_> {
1260 GetGuildMemberPermissions::new(self, guild_id, user_id)
1261 }
1262
1263 /// Add a user to a guild.
1264 ///
1265 /// An access token for the user with `guilds.join` scope is required. All
1266 /// other fields are optional. See [Discord Docs/Add Guild Member].
1267 ///
1268 /// # Errors
1269 ///
1270 /// Returns an error of type [`ValidationErrorType::Nickname`] if the
1271 /// nickname is too short or too long.
1272 ///
1273 /// [`ValidationErrorType::Nickname`]: twilight_validate::request::ValidationErrorType::Nickname
1274 /// [Discord Docs/Add Guild Member]: https://discord.com/developers/docs/resources/guild#add-guild-member
1275 pub const fn add_guild_member<'a>(
1276 &'a self,
1277 guild_id: Id<GuildMarker>,
1278 user_id: Id<UserMarker>,
1279 access_token: &'a str,
1280 ) -> AddGuildMember<'a> {
1281 AddGuildMember::new(self, guild_id, user_id, access_token)
1282 }
1283
1284 /// Kick a member from a guild.
1285 pub const fn remove_guild_member(
1286 &self,
1287 guild_id: Id<GuildMarker>,
1288 user_id: Id<UserMarker>,
1289 ) -> RemoveMember<'_> {
1290 RemoveMember::new(self, guild_id, user_id)
1291 }
1292
1293 /// Update a guild member.
1294 ///
1295 /// All fields are optional. See [Discord Docs/Modify Guild Member].
1296 ///
1297 /// # Examples
1298 ///
1299 /// Update a member's nickname to "pinky pie" and server mute them:
1300 ///
1301 /// ```no_run
1302 /// use std::env;
1303 /// use twilight_http::Client;
1304 /// use twilight_model::id::Id;
1305 ///
1306 /// # #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> {
1307 /// let client = Client::new(env::var("DISCORD_TOKEN")?);
1308 /// let member = client
1309 /// .update_guild_member(Id::new(1), Id::new(2))
1310 /// .mute(true)
1311 /// .nick(Some("pinkie pie"))
1312 /// .await?
1313 /// .model()
1314 /// .await?;
1315 ///
1316 /// println!(
1317 /// "user {} now has the nickname '{:?}'",
1318 /// member.user.id, member.nick,
1319 /// );
1320 /// # Ok(()) }
1321 /// ```
1322 ///
1323 /// # Errors
1324 ///
1325 /// Returns an error of type [`ValidationErrorType::Nickname`] if the
1326 /// nickname length is too short or too long.
1327 ///
1328 /// [`ValidationErrorType::Nickname`]: twilight_validate::request::ValidationErrorType::Nickname
1329 /// [Discord Docs/Modify Guild Member]: https://discord.com/developers/docs/resources/guild#modify-guild-member
1330 pub const fn update_guild_member(
1331 &self,
1332 guild_id: Id<GuildMarker>,
1333 user_id: Id<UserMarker>,
1334 ) -> UpdateGuildMember<'_> {
1335 UpdateGuildMember::new(self, guild_id, user_id)
1336 }
1337
1338 /// Update the user's member in a guild.
1339 pub const fn update_current_member(
1340 &self,
1341 guild_id: Id<GuildMarker>,
1342 ) -> UpdateCurrentMember<'_> {
1343 UpdateCurrentMember::new(self, guild_id)
1344 }
1345
1346 /// Add a role to a member in a guild.
1347 ///
1348 /// # Examples
1349 ///
1350 /// In guild `1`, add role `2` to user `3`, for the reason `"test"`:
1351 ///
1352 /// ```no_run
1353 /// # use twilight_http::{request::AuditLogReason, Client};
1354 /// use twilight_model::id::Id;
1355 /// #
1356 /// # #[tokio::main]
1357 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
1358 /// # let client = Client::new("my token".to_owned());
1359 /// #
1360 /// let guild_id = Id::new(1);
1361 /// let role_id = Id::new(2);
1362 /// let user_id = Id::new(3);
1363 ///
1364 /// client
1365 /// .add_guild_member_role(guild_id, user_id, role_id)
1366 /// .reason("test")
1367 /// .await?;
1368 /// # Ok(()) }
1369 /// ```
1370 pub const fn add_guild_member_role(
1371 &self,
1372 guild_id: Id<GuildMarker>,
1373 user_id: Id<UserMarker>,
1374 role_id: Id<RoleMarker>,
1375 ) -> AddRoleToMember<'_> {
1376 AddRoleToMember::new(self, guild_id, user_id, role_id)
1377 }
1378
1379 /// Remove a role from a member in a guild, by id.
1380 pub const fn remove_guild_member_role(
1381 &self,
1382 guild_id: Id<GuildMarker>,
1383 user_id: Id<UserMarker>,
1384 role_id: Id<RoleMarker>,
1385 ) -> RemoveRoleFromMember<'_> {
1386 RemoveRoleFromMember::new(self, guild_id, user_id, role_id)
1387 }
1388
1389 /// Retrieves the onboarding data for a guild.
1390 pub const fn guild_onboarding(&self, guild_id: Id<GuildMarker>) -> GetGuildOnboarding<'_> {
1391 GetGuildOnboarding::new(self, guild_id)
1392 }
1393
1394 /// For public guilds, get the guild preview.
1395 ///
1396 /// This works even if the user is not in the guild.
1397 pub const fn guild_preview(&self, guild_id: Id<GuildMarker>) -> GetGuildPreview<'_> {
1398 GetGuildPreview::new(self, guild_id)
1399 }
1400
1401 /// Get the counts of guild members to be pruned.
1402 pub const fn guild_prune_count(&self, guild_id: Id<GuildMarker>) -> GetGuildPruneCount<'_> {
1403 GetGuildPruneCount::new(self, guild_id)
1404 }
1405
1406 /// Begin a guild prune.
1407 ///
1408 /// See [Discord Docs/Begin Guild Prune].
1409 ///
1410 /// [Discord Docs/Begin Guild Prune]: https://discord.com/developers/docs/resources/guild#begin-guild-prune
1411 pub const fn create_guild_prune(&self, guild_id: Id<GuildMarker>) -> CreateGuildPrune<'_> {
1412 CreateGuildPrune::new(self, guild_id)
1413 }
1414
1415 /// Get a guild's vanity url, if there is one.
1416 pub const fn guild_vanity_url(&self, guild_id: Id<GuildMarker>) -> GetGuildVanityUrl<'_> {
1417 GetGuildVanityUrl::new(self, guild_id)
1418 }
1419
1420 /// Get voice region data for the guild.
1421 ///
1422 /// Can return VIP servers if the guild is VIP-enabled.
1423 pub const fn guild_voice_regions(&self, guild_id: Id<GuildMarker>) -> GetGuildVoiceRegions<'_> {
1424 GetGuildVoiceRegions::new(self, guild_id)
1425 }
1426
1427 /// Get the webhooks of a guild.
1428 pub const fn guild_webhooks(&self, guild_id: Id<GuildMarker>) -> GetGuildWebhooks<'_> {
1429 GetGuildWebhooks::new(self, guild_id)
1430 }
1431
1432 /// Get the guild's welcome screen.
1433 ///
1434 /// If the welcome screen is not enabled, this requires the [`MANAGE_GUILD`]
1435 /// permission.
1436 ///
1437 /// [`MANAGE_GUILD`]: twilight_model::guild::Permissions::MANAGE_GUILD
1438 pub const fn guild_welcome_screen(
1439 &self,
1440 guild_id: Id<GuildMarker>,
1441 ) -> GetGuildWelcomeScreen<'_> {
1442 GetGuildWelcomeScreen::new(self, guild_id)
1443 }
1444
1445 /// Update the guild's welcome screen.
1446 ///
1447 /// Requires the [`MANAGE_GUILD`] permission.
1448 ///
1449 /// [`MANAGE_GUILD`]: twilight_model::guild::Permissions::MANAGE_GUILD
1450 pub const fn update_guild_welcome_screen(
1451 &self,
1452 guild_id: Id<GuildMarker>,
1453 ) -> UpdateGuildWelcomeScreen<'_> {
1454 UpdateGuildWelcomeScreen::new(self, guild_id)
1455 }
1456
1457 /// Get information about an invite by its code.
1458 ///
1459 /// If [`with_counts`] is called, the returned invite will contain
1460 /// approximate member counts. If [`with_expiration`] is called, it will
1461 /// contain the expiration date.
1462 ///
1463 /// # Examples
1464 ///
1465 /// ```no_run
1466 /// # use twilight_http::Client;
1467 /// #
1468 /// # #[tokio::main]
1469 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
1470 /// # let client = Client::new("my token".to_owned());
1471 /// #
1472 /// let invite = client.invite("code").with_counts().await?;
1473 /// # Ok(()) }
1474 /// ```
1475 ///
1476 /// [`with_counts`]: crate::request::channel::invite::GetInvite::with_counts
1477 /// [`with_expiration`]: crate::request::channel::invite::GetInvite::with_expiration
1478 pub const fn invite<'a>(&'a self, code: &'a str) -> GetInvite<'a> {
1479 GetInvite::new(self, code)
1480 }
1481
1482 /// Create an invite, with options.
1483 ///
1484 /// Requires the [`CREATE_INVITE`] permission.
1485 ///
1486 /// # Examples
1487 ///
1488 /// ```no_run
1489 /// # use twilight_http::Client;
1490 /// # use twilight_model::id::Id;
1491 /// #
1492 /// # #[tokio::main]
1493 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
1494 /// # let client = Client::new("my token".to_owned());
1495 /// #
1496 /// let channel_id = Id::new(123);
1497 /// let invite = client.create_invite(channel_id).max_uses(3).await?;
1498 /// # Ok(()) }
1499 /// ```
1500 ///
1501 /// [`CREATE_INVITE`]: twilight_model::guild::Permissions::CREATE_INVITE
1502 pub const fn create_invite(&self, channel_id: Id<ChannelMarker>) -> CreateInvite<'_> {
1503 CreateInvite::new(self, channel_id)
1504 }
1505
1506 /// Delete an invite by its code.
1507 ///
1508 /// Requires the [`MANAGE_CHANNELS`] permission on the channel this invite
1509 /// belongs to, or [`MANAGE_GUILD`] to remove any invite across the guild.
1510 ///
1511 /// [`MANAGE_CHANNELS`]: twilight_model::guild::Permissions::MANAGE_CHANNELS
1512 /// [`MANAGE_GUILD`]: twilight_model::guild::Permissions::MANAGE_GUILD
1513 pub const fn delete_invite<'a>(&'a self, code: &'a str) -> DeleteInvite<'a> {
1514 DeleteInvite::new(self, code)
1515 }
1516
1517 /// Get a message by [`Id<ChannelMarker>`] and [`Id<MessageMarker>`].
1518 pub const fn message(
1519 &self,
1520 channel_id: Id<ChannelMarker>,
1521 message_id: Id<MessageMarker>,
1522 ) -> GetMessage<'_> {
1523 GetMessage::new(self, channel_id, message_id)
1524 }
1525
1526 /// Send a message to a channel.
1527 ///
1528 /// The message must include at least one of [`attachments`],
1529 /// [`components`], [`content`], [`embeds`], or [`sticker_ids`].
1530 ///
1531 /// # Example
1532 ///
1533 /// ```no_run
1534 /// # #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> {
1535 /// use twilight_http::Client;
1536 /// use twilight_model::id::Id;
1537 ///
1538 /// let client = Client::new("my token".to_owned());
1539 ///
1540 /// let channel_id = Id::new(123);
1541 /// let message = client
1542 /// .create_message(channel_id)
1543 /// .content("Twilight is best pony")
1544 /// .tts(true)
1545 /// .await?;
1546 /// # Ok(()) }
1547 /// ```
1548 ///
1549 /// [`attachments`]: CreateMessage::attachments
1550 /// [`components`]: CreateMessage::components
1551 /// [`content`]: CreateMessage::content
1552 /// [`embeds`]: CreateMessage::embeds
1553 /// [`sticker_ids`]: CreateMessage::sticker_ids
1554 pub const fn create_message(&self, channel_id: Id<ChannelMarker>) -> CreateMessage<'_> {
1555 CreateMessage::new(self, channel_id)
1556 }
1557
1558 /// Delete a message by [`Id<ChannelMarker>`] and [`Id<MessageMarker>`].
1559 pub const fn delete_message(
1560 &self,
1561 channel_id: Id<ChannelMarker>,
1562 message_id: Id<MessageMarker>,
1563 ) -> DeleteMessage<'_> {
1564 DeleteMessage::new(self, channel_id, message_id)
1565 }
1566
1567 /// Delete messages by [`Id<ChannelMarker>`] and Vec<[`Id<MessageMarker>`]>.
1568 ///
1569 /// The vec count can be between 2 and 100. If the supplied
1570 /// [`Id<MessageMarker>`]s are invalid, they still count towards the lower
1571 /// and upper limits. This method will not delete messages older than two
1572 /// weeks. See [Discord Docs/Bulk Delete Messages].
1573 ///
1574 /// # Errors
1575 ///
1576 /// Returns an error of type
1577 /// [`ChannelValidationErrorType::BulkDeleteMessagesInvalid`] when the number of
1578 /// messages to delete in bulk is invalid.
1579 ///
1580 /// [Discord Docs/Bulk Delete Messages]: https://discord.com/developers/docs/resources/channel#bulk-delete-messages
1581 /// [`ChannelValidationErrorType::BulkDeleteMessagesInvalid`]: twilight_validate::channel::ChannelValidationErrorType::BulkDeleteMessagesInvalid
1582 pub fn delete_messages<'a>(
1583 &'a self,
1584 channel_id: Id<ChannelMarker>,
1585 message_ids: &'a [Id<MessageMarker>],
1586 ) -> DeleteMessages<'a> {
1587 DeleteMessages::new(self, channel_id, message_ids)
1588 }
1589
1590 /// Update a message by [`Id<ChannelMarker>`] and [`Id<MessageMarker>`].
1591 ///
1592 /// You can pass [`None`] to any of the methods to remove the associated
1593 /// field. Pass [`None`] to [`content`] to remove the content. You must
1594 /// ensure that the message still contains at least one of [`attachments`],
1595 /// [`components`], [`content`], [`embeds`], or stickers.
1596 ///
1597 /// # Examples
1598 ///
1599 /// Replace the content with `"test update"`:
1600 ///
1601 /// ```no_run
1602 /// # #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> {
1603 /// use twilight_http::Client;
1604 /// use twilight_model::id::Id;
1605 ///
1606 /// let client = Client::new("my token".to_owned());
1607 /// client
1608 /// .update_message(Id::new(1), Id::new(2))
1609 /// .content(Some("test update"))
1610 /// .await?;
1611 /// # Ok(()) }
1612 /// ```
1613 ///
1614 /// Remove the message's content:
1615 ///
1616 /// ```no_run
1617 /// # use twilight_http::Client;
1618 /// # use twilight_model::id::Id;
1619 /// #
1620 /// # #[tokio::main]
1621 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
1622 /// # let client = Client::new("my token".to_owned());
1623 /// client
1624 /// .update_message(Id::new(1), Id::new(2))
1625 /// .content(None)
1626 /// .await?;
1627 /// # Ok(()) }
1628 /// ```
1629 ///
1630 /// [`attachments`]: UpdateMessage::attachments
1631 /// [`components`]: UpdateMessage::components
1632 /// [`content`]: UpdateMessage::content
1633 /// [`embeds`]: UpdateMessage::embeds
1634 pub const fn update_message(
1635 &self,
1636 channel_id: Id<ChannelMarker>,
1637 message_id: Id<MessageMarker>,
1638 ) -> UpdateMessage<'_> {
1639 UpdateMessage::new(self, channel_id, message_id)
1640 }
1641
1642 /// Crosspost a message by [`Id<ChannelMarker>`] and [`Id<MessageMarker>`].
1643 pub const fn crosspost_message(
1644 &self,
1645 channel_id: Id<ChannelMarker>,
1646 message_id: Id<MessageMarker>,
1647 ) -> CrosspostMessage<'_> {
1648 CrosspostMessage::new(self, channel_id, message_id)
1649 }
1650
1651 /// Get the pins of a channel.
1652 pub const fn pins(&self, channel_id: Id<ChannelMarker>) -> GetPins<'_> {
1653 GetPins::new(self, channel_id)
1654 }
1655
1656 /// Create a new pin in a channel, by ID.
1657 pub const fn create_pin(
1658 &self,
1659 channel_id: Id<ChannelMarker>,
1660 message_id: Id<MessageMarker>,
1661 ) -> CreatePin<'_> {
1662 CreatePin::new(self, channel_id, message_id)
1663 }
1664
1665 /// Delete a pin in a channel, by ID.
1666 pub const fn delete_pin(
1667 &self,
1668 channel_id: Id<ChannelMarker>,
1669 message_id: Id<MessageMarker>,
1670 ) -> DeletePin<'_> {
1671 DeletePin::new(self, channel_id, message_id)
1672 }
1673
1674 /// Get a list of users that reacted to a message with an `emoji`.
1675 ///
1676 /// This endpoint is limited to 100 users maximum, so if a message has more than 100 reactions,
1677 /// requests must be chained until all reactions are retrieved.
1678 pub const fn reactions<'a>(
1679 &'a self,
1680 channel_id: Id<ChannelMarker>,
1681 message_id: Id<MessageMarker>,
1682 emoji: &'a RequestReactionType<'a>,
1683 ) -> GetReactions<'a> {
1684 GetReactions::new(self, channel_id, message_id, emoji)
1685 }
1686
1687 /// Create a reaction in a [`Id<ChannelMarker>`] on a [`Id<MessageMarker>`].
1688 ///
1689 /// The reaction must be a variant of [`RequestReactionType`].
1690 ///
1691 /// # Examples
1692 /// ```no_run
1693 /// # use twilight_http::{Client, request::channel::reaction::RequestReactionType};
1694 /// # use twilight_model::id::Id;
1695 /// #
1696 /// # #[tokio::main]
1697 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
1698 /// # let client = Client::new("my token".to_owned());
1699 /// #
1700 /// let channel_id = Id::new(123);
1701 /// let message_id = Id::new(456);
1702 /// let emoji = RequestReactionType::Unicode { name: "🌃" };
1703 ///
1704 /// let reaction = client
1705 /// .create_reaction(channel_id, message_id, &emoji)
1706 /// .await?;
1707 /// # Ok(()) }
1708 /// ```
1709 pub const fn create_reaction<'a>(
1710 &'a self,
1711 channel_id: Id<ChannelMarker>,
1712 message_id: Id<MessageMarker>,
1713 emoji: &'a RequestReactionType<'a>,
1714 ) -> CreateReaction<'a> {
1715 CreateReaction::new(self, channel_id, message_id, emoji)
1716 }
1717
1718 /// Delete the current user's (`@me`) reaction on a message.
1719 pub const fn delete_current_user_reaction<'a>(
1720 &'a self,
1721 channel_id: Id<ChannelMarker>,
1722 message_id: Id<MessageMarker>,
1723 emoji: &'a RequestReactionType<'a>,
1724 ) -> DeleteReaction<'a> {
1725 DeleteReaction::new(self, channel_id, message_id, emoji, TargetUser::Current)
1726 }
1727
1728 /// Delete a reaction by a user on a message.
1729 pub const fn delete_reaction<'a>(
1730 &'a self,
1731 channel_id: Id<ChannelMarker>,
1732 message_id: Id<MessageMarker>,
1733 emoji: &'a RequestReactionType<'a>,
1734 user_id: Id<UserMarker>,
1735 ) -> DeleteReaction<'a> {
1736 DeleteReaction::new(self, channel_id, message_id, emoji, TargetUser::Id(user_id))
1737 }
1738
1739 /// Remove all reactions on a message of an emoji.
1740 pub const fn delete_all_reaction<'a>(
1741 &'a self,
1742 channel_id: Id<ChannelMarker>,
1743 message_id: Id<MessageMarker>,
1744 emoji: &'a RequestReactionType<'a>,
1745 ) -> DeleteAllReaction<'a> {
1746 DeleteAllReaction::new(self, channel_id, message_id, emoji)
1747 }
1748
1749 /// Delete all reactions by all users on a message.
1750 pub const fn delete_all_reactions(
1751 &self,
1752 channel_id: Id<ChannelMarker>,
1753 message_id: Id<MessageMarker>,
1754 ) -> DeleteAllReactions<'_> {
1755 DeleteAllReactions::new(self, channel_id, message_id)
1756 }
1757
1758 /// Fire a Typing Start event in the channel.
1759 pub const fn create_typing_trigger(
1760 &self,
1761 channel_id: Id<ChannelMarker>,
1762 ) -> CreateTypingTrigger<'_> {
1763 CreateTypingTrigger::new(self, channel_id)
1764 }
1765
1766 /// Create a DM channel with a user.
1767 pub const fn create_private_channel(
1768 &self,
1769 recipient_id: Id<UserMarker>,
1770 ) -> CreatePrivateChannel<'_> {
1771 CreatePrivateChannel::new(self, recipient_id)
1772 }
1773
1774 /// Get the roles of a guild.
1775 pub const fn roles(&self, guild_id: Id<GuildMarker>) -> GetGuildRoles<'_> {
1776 GetGuildRoles::new(self, guild_id)
1777 }
1778
1779 /// Get the role member counts of a guild.
1780 pub const fn role_member_counts(
1781 &self,
1782 guild_id: Id<GuildMarker>,
1783 ) -> GetGuildRoleMemberCounts<'_> {
1784 GetGuildRoleMemberCounts::new(self, guild_id)
1785 }
1786
1787 /// Get a role of a guild.
1788 pub const fn role(&self, guild_id: Id<GuildMarker>, role_id: Id<RoleMarker>) -> GetRole<'_> {
1789 GetRole::new(self, guild_id, role_id)
1790 }
1791
1792 /// Get the combined guild permissions of the specified role and
1793 /// `@everyone`.
1794 ///
1795 /// This calculation does not include other roles or member-specific
1796 /// restrictions.
1797 pub const fn role_permissions(
1798 &self,
1799 guild_id: Id<GuildMarker>,
1800 role_id: Id<RoleMarker>,
1801 ) -> GetGuildRolePermissions<'_> {
1802 GetGuildRolePermissions::new(self, guild_id, role_id)
1803 }
1804
1805 /// Create a role in a guild.
1806 ///
1807 /// # Examples
1808 ///
1809 /// ```no_run
1810 /// # use twilight_http::Client;
1811 /// use twilight_model::id::Id;
1812 ///
1813 /// # #[tokio::main]
1814 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
1815 /// # let client = Client::new("my token".to_owned());
1816 /// let guild_id = Id::new(234);
1817 ///
1818 /// client
1819 /// .create_role(guild_id)
1820 /// .color(0xd90083)
1821 /// .name("Bright Pink")
1822 /// .await?;
1823 /// # Ok(()) }
1824 /// ```
1825 pub const fn create_role(&self, guild_id: Id<GuildMarker>) -> CreateRole<'_> {
1826 CreateRole::new(self, guild_id)
1827 }
1828
1829 /// Delete a role in a guild, by id.
1830 pub const fn delete_role(
1831 &self,
1832 guild_id: Id<GuildMarker>,
1833 role_id: Id<RoleMarker>,
1834 ) -> DeleteRole<'_> {
1835 DeleteRole::new(self, guild_id, role_id)
1836 }
1837
1838 /// Update a role by guild id and its id.
1839 pub const fn update_role(
1840 &self,
1841 guild_id: Id<GuildMarker>,
1842 role_id: Id<RoleMarker>,
1843 ) -> UpdateRole<'_> {
1844 UpdateRole::new(self, guild_id, role_id)
1845 }
1846
1847 /// Modify the position of the roles.
1848 ///
1849 /// The minimum amount of roles to modify, is a swap between two roles.
1850 pub const fn update_role_positions<'a>(
1851 &'a self,
1852 guild_id: Id<GuildMarker>,
1853 roles: &'a [RolePosition],
1854 ) -> UpdateRolePositions<'a> {
1855 UpdateRolePositions::new(self, guild_id, roles)
1856 }
1857
1858 /// Create a new stage instance associated with a stage channel.
1859 ///
1860 /// Requires the user to be a moderator of the stage channel.
1861 ///
1862 /// # Errors
1863 ///
1864 /// Returns an error of type [`ValidationError::StageTopic`] when the topic
1865 /// is not between 1 and 120 characters in length.
1866 ///
1867 /// [`ValidationError::StageTopic`]: twilight_validate::request::ValidationErrorType::StageTopic
1868 pub fn create_stage_instance<'a>(
1869 &'a self,
1870 channel_id: Id<ChannelMarker>,
1871 topic: &'a str,
1872 ) -> CreateStageInstance<'a> {
1873 CreateStageInstance::new(self, channel_id, topic)
1874 }
1875
1876 /// Gets the stage instance associated with a stage channel, if it exists.
1877 pub const fn stage_instance(&self, channel_id: Id<ChannelMarker>) -> GetStageInstance<'_> {
1878 GetStageInstance::new(self, channel_id)
1879 }
1880
1881 /// Update fields of an existing stage instance.
1882 ///
1883 /// Requires the user to be a moderator of the stage channel.
1884 pub const fn update_stage_instance(
1885 &self,
1886 channel_id: Id<ChannelMarker>,
1887 ) -> UpdateStageInstance<'_> {
1888 UpdateStageInstance::new(self, channel_id)
1889 }
1890
1891 /// Delete the stage instance of a stage channel.
1892 ///
1893 /// Requires the user to be a moderator of the stage channel.
1894 pub const fn delete_stage_instance(
1895 &self,
1896 channel_id: Id<ChannelMarker>,
1897 ) -> DeleteStageInstance<'_> {
1898 DeleteStageInstance::new(self, channel_id)
1899 }
1900
1901 /// Create a new guild based on a template.
1902 ///
1903 /// This endpoint can only be used by bots in less than 10 guilds.
1904 ///
1905 /// # Errors
1906 ///
1907 /// Returns an error of type [`ValidationErrorType::TemplateName`] if the
1908 /// name is invalid.
1909 ///
1910 /// [`ValidationErrorType::TemplateName`]: twilight_validate::request::ValidationErrorType::TemplateName
1911 pub fn create_guild_from_template<'a>(
1912 &'a self,
1913 template_code: &'a str,
1914 name: &'a str,
1915 ) -> CreateGuildFromTemplate<'a> {
1916 CreateGuildFromTemplate::new(self, template_code, name)
1917 }
1918
1919 /// Create a template from the current state of the guild.
1920 ///
1921 /// Requires the `MANAGE_GUILD` permission. The name must be at least 1 and
1922 /// at most 100 characters in length.
1923 ///
1924 /// # Errors
1925 ///
1926 /// Returns an error of type [`ValidationErrorType::TemplateName`] if the
1927 /// name is invalid.
1928 ///
1929 /// [`ValidationErrorType::TemplateName`]: twilight_validate::request::ValidationErrorType::TemplateName
1930 pub fn create_template<'a>(
1931 &'a self,
1932 guild_id: Id<GuildMarker>,
1933 name: &'a str,
1934 ) -> CreateTemplate<'a> {
1935 CreateTemplate::new(self, guild_id, name)
1936 }
1937
1938 /// Delete a template by ID and code.
1939 pub const fn delete_template<'a>(
1940 &'a self,
1941 guild_id: Id<GuildMarker>,
1942 template_code: &'a str,
1943 ) -> DeleteTemplate<'a> {
1944 DeleteTemplate::new(self, guild_id, template_code)
1945 }
1946
1947 /// Get a template by its code.
1948 pub const fn get_template<'a>(&'a self, template_code: &'a str) -> GetTemplate<'a> {
1949 GetTemplate::new(self, template_code)
1950 }
1951
1952 /// Get a list of templates in a guild, by ID.
1953 pub const fn get_templates(&self, guild_id: Id<GuildMarker>) -> GetTemplates<'_> {
1954 GetTemplates::new(self, guild_id)
1955 }
1956
1957 /// Sync a template to the current state of the guild, by ID and code.
1958 pub const fn sync_template<'a>(
1959 &'a self,
1960 guild_id: Id<GuildMarker>,
1961 template_code: &'a str,
1962 ) -> SyncTemplate<'a> {
1963 SyncTemplate::new(self, guild_id, template_code)
1964 }
1965
1966 /// Update the template's metadata, by ID and code.
1967 pub const fn update_template<'a>(
1968 &'a self,
1969 guild_id: Id<GuildMarker>,
1970 template_code: &'a str,
1971 ) -> UpdateTemplate<'a> {
1972 UpdateTemplate::new(self, guild_id, template_code)
1973 }
1974
1975 /// Returns all active threads in the guild.
1976 ///
1977 /// Includes public and private threads. Threads are ordered by their ID in
1978 /// descending order.
1979 ///
1980 /// # Examples
1981 ///
1982 /// ```no_run
1983 /// # #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> {
1984 /// use twilight_http::Client;
1985 /// use twilight_model::id::Id;
1986 ///
1987 /// let client = Client::new("my token".to_owned());
1988 /// let guild_id = Id::new(234);
1989 ///
1990 /// let threads = client.active_threads(guild_id).await?.model().await?;
1991 /// # Ok(()) }
1992 /// ```
1993 pub const fn active_threads(&self, guild_id: Id<GuildMarker>) -> GetActiveThreads<'_> {
1994 GetActiveThreads::new(self, guild_id)
1995 }
1996
1997 /// Add another member to a thread.
1998 ///
1999 /// Requires the ability to send messages in the thread, and that the thread
2000 /// is not archived.
2001 pub const fn add_thread_member(
2002 &self,
2003 channel_id: Id<ChannelMarker>,
2004 user_id: Id<UserMarker>,
2005 ) -> AddThreadMember<'_> {
2006 AddThreadMember::new(self, channel_id, user_id)
2007 }
2008
2009 /// Start a thread in a forum channel.
2010 pub const fn create_forum_thread<'a>(
2011 &'a self,
2012 channel_id: Id<ChannelMarker>,
2013 name: &'a str,
2014 ) -> CreateForumThread<'a> {
2015 CreateForumThread::new(self, channel_id, name)
2016 }
2017
2018 /// Start a thread that is not connected to a message.
2019 ///
2020 /// Automatic archive durations are not locked behind the guild's boost
2021 /// level.
2022 ///
2023 /// To make a [`PrivateThread`], the guild must also have the
2024 /// `PRIVATE_THREADS` feature.
2025 ///
2026 /// # Errors
2027 ///
2028 /// Returns an error of type [`NameInvalid`] if the channel's name's length is
2029 /// incorrect.
2030 ///
2031 /// Returns an error of type [`TypeInvalid`] if the channel is not a thread.
2032 ///
2033 /// [`NameInvalid`]: twilight_validate::channel::ChannelValidationErrorType::NameInvalid
2034 /// [`PrivateThread`]: twilight_model::channel::ChannelType::PrivateThread
2035 /// [`TypeInvalid`]: twilight_validate::channel::ChannelValidationErrorType::TypeInvalid
2036 pub fn create_thread<'a>(
2037 &'a self,
2038 channel_id: Id<ChannelMarker>,
2039 name: &'a str,
2040 kind: ChannelType,
2041 ) -> CreateThread<'a> {
2042 CreateThread::new(self, channel_id, name, kind)
2043 }
2044
2045 /// Create a new thread from an existing message.
2046 ///
2047 /// When called on a [`GuildText`] channel, this creates a
2048 /// [`PublicThread`].
2049 ///
2050 /// When called on a [`GuildAnnouncement`] channel, this creates a
2051 /// [`AnnouncementThread`].
2052 ///
2053 /// Automatic archive durations are not locked behind the guild's boost
2054 /// level.
2055 ///
2056 /// The thread's ID will be the same as its parent message. This ensures
2057 /// only one thread can be created per message.
2058 ///
2059 /// # Errors
2060 ///
2061 /// Returns an error of type [`NameInvalid`] if the channel's name's length is
2062 /// incorrect.
2063 ///
2064 /// Returns an error of type [`TypeInvalid`] if the channel is not a thread.
2065 ///
2066 /// [`AnnouncementThread`]: twilight_model::channel::ChannelType::AnnouncementThread
2067 /// [`GuildAnnouncement`]: twilight_model::channel::ChannelType::GuildAnnouncement
2068 /// [`GuildText`]: twilight_model::channel::ChannelType::GuildText
2069 /// [`NameInvalid`]: twilight_validate::channel::ChannelValidationErrorType::NameInvalid
2070 /// [`PublicThread`]: twilight_model::channel::ChannelType::PublicThread
2071 /// [`TypeInvalid`]: twilight_validate::channel::ChannelValidationErrorType::TypeInvalid
2072 pub fn create_thread_from_message<'a>(
2073 &'a self,
2074 channel_id: Id<ChannelMarker>,
2075 message_id: Id<MessageMarker>,
2076 name: &'a str,
2077 ) -> CreateThreadFromMessage<'a> {
2078 CreateThreadFromMessage::new(self, channel_id, message_id, name)
2079 }
2080
2081 /// Add the current user to a thread.
2082 pub const fn join_thread(&self, channel_id: Id<ChannelMarker>) -> JoinThread<'_> {
2083 JoinThread::new(self, channel_id)
2084 }
2085
2086 /// Returns archived private threads in the channel that the current user
2087 /// has joined.
2088 ///
2089 /// Threads are ordered by their ID in descending order.
2090 pub const fn joined_private_archived_threads(
2091 &self,
2092 channel_id: Id<ChannelMarker>,
2093 ) -> GetJoinedPrivateArchivedThreads<'_> {
2094 GetJoinedPrivateArchivedThreads::new(self, channel_id)
2095 }
2096
2097 /// Remove the current user from a thread.
2098 ///
2099 /// Requires that the thread is not archived.
2100 pub const fn leave_thread(&self, channel_id: Id<ChannelMarker>) -> LeaveThread<'_> {
2101 LeaveThread::new(self, channel_id)
2102 }
2103
2104 /// Returns archived private threads in the channel.
2105 ///
2106 /// Requires both [`READ_MESSAGE_HISTORY`] and [`MANAGE_THREADS`].
2107 ///
2108 /// [`MANAGE_THREADS`]: twilight_model::guild::Permissions::MANAGE_THREADS
2109 /// [`READ_MESSAGE_HISTORY`]: twilight_model::guild::Permissions::READ_MESSAGE_HISTORY
2110 pub const fn private_archived_threads(
2111 &self,
2112 channel_id: Id<ChannelMarker>,
2113 ) -> GetPrivateArchivedThreads<'_> {
2114 GetPrivateArchivedThreads::new(self, channel_id)
2115 }
2116
2117 /// Returns archived public threads in the channel.
2118 ///
2119 /// Requires the [`READ_MESSAGE_HISTORY`] permission.
2120 ///
2121 /// Threads are ordered by [`archive_timestamp`] in descending order.
2122 ///
2123 /// When called in a [`GuildText`] channel, returns [`PublicThread`]s.
2124 ///
2125 /// When called in a [`GuildAnnouncement`] channel, returns [`AnnouncementThread`]s.
2126 ///
2127 /// [`AnnouncementThread`]: twilight_model::channel::ChannelType::AnnouncementThread
2128 /// [`archive_timestamp`]: twilight_model::channel::thread::ThreadMetadata::archive_timestamp
2129 /// [`GuildAnnouncement`]: twilight_model::channel::ChannelType::GuildAnnouncement
2130 /// [`GuildText`]: twilight_model::channel::ChannelType::GuildText
2131 /// [`PublicThread`]: twilight_model::channel::ChannelType::PublicThread
2132 /// [`READ_MESSAGE_HISTORY`]: twilight_model::guild::Permissions::READ_MESSAGE_HISTORY
2133 pub const fn public_archived_threads(
2134 &self,
2135 channel_id: Id<ChannelMarker>,
2136 ) -> GetPublicArchivedThreads<'_> {
2137 GetPublicArchivedThreads::new(self, channel_id)
2138 }
2139
2140 /// Remove another member from a thread.
2141 ///
2142 /// Requires that the thread is not archived.
2143 ///
2144 /// Requires the [`MANAGE_THREADS`] permission, unless both the thread is a
2145 /// [`PrivateThread`], and the current user is the creator of the
2146 /// thread.
2147 ///
2148 /// [`MANAGE_THREADS`]: twilight_model::guild::Permissions::MANAGE_THREADS
2149 /// [`PrivateThread`]: twilight_model::channel::ChannelType::PrivateThread
2150 pub const fn remove_thread_member(
2151 &self,
2152 channel_id: Id<ChannelMarker>,
2153 user_id: Id<UserMarker>,
2154 ) -> RemoveThreadMember<'_> {
2155 RemoveThreadMember::new(self, channel_id, user_id)
2156 }
2157
2158 /// Returns a [`ThreadMember`] in a thread.
2159 ///
2160 /// [`ThreadMember`]: twilight_model::channel::thread::ThreadMember
2161 pub const fn thread_member(
2162 &self,
2163 channel_id: Id<ChannelMarker>,
2164 user_id: Id<UserMarker>,
2165 ) -> GetThreadMember<'_> {
2166 GetThreadMember::new(self, channel_id, user_id)
2167 }
2168
2169 /// Returns the [`ThreadMember`]s of the thread.
2170 ///
2171 /// [`ThreadMember`]: twilight_model::channel::thread::ThreadMember
2172 pub const fn thread_members(&self, channel_id: Id<ChannelMarker>) -> GetThreadMembers<'_> {
2173 GetThreadMembers::new(self, channel_id)
2174 }
2175
2176 /// Update a thread.
2177 ///
2178 /// All fields are optional. The minimum length of the name is 1 UTF-16
2179 /// characters and the maximum is 100 UTF-16 characters.
2180 pub const fn update_thread(&self, channel_id: Id<ChannelMarker>) -> UpdateThread<'_> {
2181 UpdateThread::new(self, channel_id)
2182 }
2183
2184 /// Get a user's information by id.
2185 pub const fn user(&self, user_id: Id<UserMarker>) -> GetUser<'_> {
2186 GetUser::new(self, user_id)
2187 }
2188
2189 /// Get voice state of a user in a guild.
2190 ///
2191 /// # Caveats
2192 ///
2193 /// - User must already have joined a voice/stage channel in this guild.
2194 pub const fn user_voice_state(
2195 &self,
2196 guild_id: Id<GuildMarker>,
2197 user_id: Id<UserMarker>,
2198 ) -> GetUserVoiceState<'_> {
2199 GetUserVoiceState::new(self, guild_id, user_id)
2200 }
2201
2202 /// Update another user's voice state.
2203 ///
2204 /// # Caveats
2205 ///
2206 /// - `channel_id` must currently point to a stage channel.
2207 /// - User must already have joined `channel_id`.
2208 pub const fn update_user_voice_state(
2209 &self,
2210 guild_id: Id<GuildMarker>,
2211 user_id: Id<UserMarker>,
2212 channel_id: Id<ChannelMarker>,
2213 ) -> UpdateUserVoiceState<'_> {
2214 UpdateUserVoiceState::new(self, guild_id, user_id, channel_id)
2215 }
2216
2217 /// Get a list of voice regions that can be used when creating a guild.
2218 pub const fn voice_regions(&self) -> GetVoiceRegions<'_> {
2219 GetVoiceRegions::new(self)
2220 }
2221
2222 /// Get a webhook by ID.
2223 pub const fn webhook(&self, id: Id<WebhookMarker>) -> GetWebhook<'_> {
2224 GetWebhook::new(self, id)
2225 }
2226
2227 /// Create a webhook in a channel.
2228 ///
2229 /// # Examples
2230 ///
2231 /// ```no_run
2232 /// # use twilight_http::Client;
2233 /// # use twilight_model::id::Id;
2234 /// #
2235 /// # #[tokio::main]
2236 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
2237 /// # let client = Client::new("my token".to_owned());
2238 /// let channel_id = Id::new(123);
2239 ///
2240 /// let webhook = client.create_webhook(channel_id, "Twily Bot").await?;
2241 /// # Ok(()) }
2242 /// ```
2243 ///
2244 /// # Errors
2245 ///
2246 /// Returns an error of type [`WebhookUsername`] if the webhook's name is
2247 /// invalid.
2248 ///
2249 /// [`WebhookUsername`]: twilight_validate::request::ValidationErrorType::WebhookUsername
2250 pub fn create_webhook<'a>(
2251 &'a self,
2252 channel_id: Id<ChannelMarker>,
2253 name: &'a str,
2254 ) -> CreateWebhook<'a> {
2255 CreateWebhook::new(self, channel_id, name)
2256 }
2257
2258 /// Delete a webhook by its ID.
2259 pub const fn delete_webhook(&self, id: Id<WebhookMarker>) -> DeleteWebhook<'_> {
2260 DeleteWebhook::new(self, id)
2261 }
2262
2263 /// Update a webhook by ID.
2264 pub const fn update_webhook(&self, webhook_id: Id<WebhookMarker>) -> UpdateWebhook<'_> {
2265 UpdateWebhook::new(self, webhook_id)
2266 }
2267
2268 /// Update a webhook, with a token, by ID.
2269 pub const fn update_webhook_with_token<'a>(
2270 &'a self,
2271 webhook_id: Id<WebhookMarker>,
2272 token: &'a str,
2273 ) -> UpdateWebhookWithToken<'a> {
2274 UpdateWebhookWithToken::new(self, webhook_id, token)
2275 }
2276
2277 /// Execute a webhook, sending a message to its channel.
2278 ///
2279 /// The message must include at least one of [`attachments`], [`components`]
2280 /// [`content`], or [`embeds`].
2281 ///
2282 /// # Examples
2283 ///
2284 /// ```no_run
2285 /// # #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> {
2286 /// use twilight_http::Client;
2287 /// use twilight_model::id::Id;
2288 ///
2289 /// let client = Client::new("my token".to_owned());
2290 /// let id = Id::new(432);
2291 ///
2292 /// let webhook = client
2293 /// .execute_webhook(id, "webhook token")
2294 /// .content("Pinkie...")
2295 /// .await?;
2296 /// # Ok(()) }
2297 /// ```
2298 ///
2299 /// [`attachments`]: ExecuteWebhook::attachments
2300 /// [`components`]: ExecuteWebhook::components
2301 /// [`content`]: ExecuteWebhook::content
2302 /// [`embeds`]: ExecuteWebhook::embeds
2303 pub const fn execute_webhook<'a>(
2304 &'a self,
2305 webhook_id: Id<WebhookMarker>,
2306 token: &'a str,
2307 ) -> ExecuteWebhook<'a> {
2308 ExecuteWebhook::new(self, webhook_id, token)
2309 }
2310
2311 /// Get a webhook message by webhook ID, token, and message ID.
2312 pub const fn webhook_message<'a>(
2313 &'a self,
2314 webhook_id: Id<WebhookMarker>,
2315 token: &'a str,
2316 message_id: Id<MessageMarker>,
2317 ) -> GetWebhookMessage<'a> {
2318 GetWebhookMessage::new(self, webhook_id, token, message_id)
2319 }
2320
2321 /// Update a message executed by a webhook.
2322 ///
2323 /// You can pass [`None`] to any of the methods to remove the associated
2324 /// field. Pass [`None`] to [`content`] to remove the content. You must
2325 /// ensure that the message still contains at least one of [`attachments`],
2326 /// [`components`], [`content`], or [`embeds`].
2327 ///
2328 /// # Examples
2329 ///
2330 /// ```no_run
2331 /// # #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> {
2332 /// use twilight_http::Client;
2333 /// use twilight_model::id::Id;
2334 ///
2335 /// let client = Client::new("token".to_owned());
2336 /// client
2337 /// .update_webhook_message(Id::new(1), "token here", Id::new(2))
2338 /// .content(Some("new message content"))
2339 /// .await?;
2340 /// # Ok(()) }
2341 /// ```
2342 ///
2343 /// [`attachments`]: UpdateWebhookMessage::attachments
2344 /// [`components`]: UpdateWebhookMessage::components
2345 /// [`content`]: UpdateWebhookMessage::content
2346 /// [`embeds`]: UpdateWebhookMessage::embeds
2347 pub const fn update_webhook_message<'a>(
2348 &'a self,
2349 webhook_id: Id<WebhookMarker>,
2350 token: &'a str,
2351 message_id: Id<MessageMarker>,
2352 ) -> UpdateWebhookMessage<'a> {
2353 UpdateWebhookMessage::new(self, webhook_id, token, message_id)
2354 }
2355
2356 /// Delete a message executed by a webhook.
2357 ///
2358 /// # Examples
2359 ///
2360 /// ```no_run
2361 /// # use twilight_http::Client;
2362 /// use twilight_model::id::Id;
2363 ///
2364 /// # #[tokio::main]
2365 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
2366 /// # let client = Client::new("token".to_owned());
2367 /// client
2368 /// .delete_webhook_message(Id::new(1), "token here", Id::new(2))
2369 /// .await?;
2370 /// # Ok(()) }
2371 /// ```
2372 pub const fn delete_webhook_message<'a>(
2373 &'a self,
2374 webhook_id: Id<WebhookMarker>,
2375 token: &'a str,
2376 message_id: Id<MessageMarker>,
2377 ) -> DeleteWebhookMessage<'a> {
2378 DeleteWebhookMessage::new(self, webhook_id, token, message_id)
2379 }
2380
2381 /// Delete a scheduled event in a guild.
2382 ///
2383 /// # Examples
2384 ///
2385 /// ```no_run
2386 /// # use twilight_http::Client;
2387 /// # use twilight_model::id::Id;
2388 /// # #[tokio::main]
2389 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
2390 /// # let client = Client::new("token".to_owned());
2391 /// let guild_id = Id::new(1);
2392 /// let scheduled_event_id = Id::new(2);
2393 ///
2394 /// client
2395 /// .delete_guild_scheduled_event(guild_id, scheduled_event_id)
2396 /// .await?;
2397 /// # Ok(()) }
2398 /// ```
2399 pub const fn delete_guild_scheduled_event(
2400 &self,
2401 guild_id: Id<GuildMarker>,
2402 scheduled_event_id: Id<ScheduledEventMarker>,
2403 ) -> DeleteGuildScheduledEvent<'_> {
2404 DeleteGuildScheduledEvent::new(self, guild_id, scheduled_event_id)
2405 }
2406
2407 /// Create a scheduled event in a guild.
2408 ///
2409 /// Once a guild is selected, you must choose one of three event types to
2410 /// create. The request builders will ensure you provide the correct data to
2411 /// Discord. See [Discord Docs/Create Guild Scheduled Event].
2412 ///
2413 /// The name must be between 1 and 100 characters in length. For external
2414 /// events, the location must be between 1 and 100 characters in length.
2415 ///
2416 /// # Examples
2417 ///
2418 /// Create an event in a stage instance:
2419 ///
2420 /// ```no_run
2421 /// # use twilight_http::Client;
2422 /// use twilight_model::{guild::scheduled_event::PrivacyLevel, id::Id, util::Timestamp};
2423 /// # #[tokio::main]
2424 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
2425 /// # let client = Client::new("token".to_owned());
2426 /// let guild_id = Id::new(1);
2427 /// let channel_id = Id::new(2);
2428 /// let garfield_start_time = Timestamp::parse("2022-01-01T14:00:00+00:00")?;
2429 ///
2430 /// client
2431 /// .create_guild_scheduled_event(guild_id, PrivacyLevel::GuildOnly)
2432 /// .stage_instance(
2433 /// channel_id,
2434 /// "Garfield Appreciation Hour",
2435 /// &garfield_start_time,
2436 /// )
2437 /// .description("Discuss: How important is Garfield to You?")
2438 /// .await?;
2439 /// # Ok(()) }
2440 /// ```
2441 ///
2442 /// Create an external event:
2443 ///
2444 /// ```no_run
2445 /// # use twilight_http::Client;
2446 /// use twilight_model::{guild::scheduled_event::PrivacyLevel, id::Id, util::Timestamp};
2447 /// # #[tokio::main]
2448 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
2449 /// # let client = Client::new("token".to_owned());
2450 /// let guild_id = Id::new(1);
2451 /// let garfield_con_start_time = Timestamp::parse("2022-01-04T08:00:00+00:00")?;
2452 /// let garfield_con_end_time = Timestamp::parse("2022-01-06T17:00:00+00:00")?;
2453 ///
2454 /// client
2455 /// .create_guild_scheduled_event(guild_id, PrivacyLevel::GuildOnly)
2456 /// .external(
2457 /// "Garfield Con 2022",
2458 /// "Baltimore Convention Center",
2459 /// &garfield_con_start_time,
2460 /// &garfield_con_end_time,
2461 /// )
2462 /// .description(
2463 /// "In a spiritual successor to BronyCon, Garfield fans from \
2464 /// around the globe celebrate all things related to the loveable cat.",
2465 /// )
2466 /// .await?;
2467 /// # Ok(()) }
2468 /// ```
2469 ///
2470 /// [Discord Docs/Create Guild Scheduled Event]: https://discord.com/developers/docs/resources/guild-scheduled-event#create-guild-scheduled-event
2471 pub const fn create_guild_scheduled_event(
2472 &self,
2473 guild_id: Id<GuildMarker>,
2474 privacy_level: PrivacyLevel,
2475 ) -> CreateGuildScheduledEvent<'_> {
2476 CreateGuildScheduledEvent::new(self, guild_id, privacy_level)
2477 }
2478
2479 /// Get a scheduled event in a guild.
2480 pub const fn guild_scheduled_event(
2481 &self,
2482 guild_id: Id<GuildMarker>,
2483 scheduled_event_id: Id<ScheduledEventMarker>,
2484 ) -> GetGuildScheduledEvent<'_> {
2485 GetGuildScheduledEvent::new(self, guild_id, scheduled_event_id)
2486 }
2487
2488 /// Get a list of users subscribed to a scheduled event.
2489 ///
2490 /// Users are returned in ascending order by `user_id`. [`before`] and
2491 /// [`after`] both take a user id. If both are specified, only [`before`] is
2492 /// respected. The default [`limit`] is 100. See
2493 /// [Discord Docs/Get Guild Scheduled Event Users].
2494 ///
2495 /// [`after`]: GetGuildScheduledEventUsers::after
2496 /// [`before`]: GetGuildScheduledEventUsers::before
2497 /// [`limit`]: GetGuildScheduledEventUsers::limit
2498 /// [Discord Docs/Get Guild Scheduled Event Users]: https://discord.com/developers/docs/resources/guild-scheduled-event#get-guild-scheduled-event-users
2499 pub const fn guild_scheduled_event_users(
2500 &self,
2501 guild_id: Id<GuildMarker>,
2502 scheduled_event_id: Id<ScheduledEventMarker>,
2503 ) -> GetGuildScheduledEventUsers<'_> {
2504 GetGuildScheduledEventUsers::new(self, guild_id, scheduled_event_id)
2505 }
2506
2507 /// Get a list of scheduled events in a guild.
2508 pub const fn guild_scheduled_events(
2509 &self,
2510 guild_id: Id<GuildMarker>,
2511 ) -> GetGuildScheduledEvents<'_> {
2512 GetGuildScheduledEvents::new(self, guild_id)
2513 }
2514
2515 /// Update a scheduled event in a guild.
2516 ///
2517 /// This endpoint supports changing the type of event. When changing the
2518 /// entity type to either [`EntityType::StageInstance`] or
2519 /// [`EntityType::Voice`], an [`Id<ChannelMarker>`] must be provided if it
2520 /// does not already exist.
2521 ///
2522 /// When changing the entity type to [`EntityType::External`], the
2523 /// `channel_id` field is cleared and the [`channel_id`] method has no
2524 /// effect. Additionally, you must set a location with [`location`].
2525 ///
2526 /// [`EntityType::External`]: twilight_model::guild::scheduled_event::EntityType::External
2527 /// [`EntityType::StageInstance`]: twilight_model::guild::scheduled_event::EntityType::StageInstance
2528 /// [`EntityType::Voice`]: twilight_model::guild::scheduled_event::EntityType::Voice
2529 /// [`channel_id`]: UpdateGuildScheduledEvent::channel_id
2530 /// [`location`]: UpdateGuildScheduledEvent::location
2531 pub const fn update_guild_scheduled_event(
2532 &self,
2533 guild_id: Id<GuildMarker>,
2534 scheduled_event_id: Id<ScheduledEventMarker>,
2535 ) -> UpdateGuildScheduledEvent<'_> {
2536 UpdateGuildScheduledEvent::new(self, guild_id, scheduled_event_id)
2537 }
2538
2539 /// Returns a single sticker by its ID.
2540 ///
2541 /// # Examples
2542 ///
2543 /// ```no_run
2544 /// use twilight_http::Client;
2545 /// use twilight_model::id::Id;
2546 ///
2547 /// # #[tokio::main]
2548 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
2549 /// let client = Client::new("my token".to_owned());
2550 ///
2551 /// let id = Id::new(123);
2552 /// let sticker = client.sticker(id).await?.model().await?;
2553 ///
2554 /// println!("{sticker:#?}");
2555 /// # Ok(()) }
2556 /// ```
2557 pub const fn sticker(&self, sticker_id: Id<StickerMarker>) -> GetSticker<'_> {
2558 GetSticker::new(self, sticker_id)
2559 }
2560
2561 /// Returns a list of sticker packs available to Nitro subscribers.
2562 ///
2563 /// # Examples
2564 ///
2565 /// ```no_run
2566 /// use twilight_http::Client;
2567 ///
2568 /// # #[tokio::main]
2569 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
2570 /// let client = Client::new("my token".to_owned());
2571 ///
2572 /// let packs = client.nitro_sticker_packs().await?.model().await?;
2573 ///
2574 /// println!("{}", packs.sticker_packs.len());
2575 /// # Ok(()) }
2576 /// ```
2577 pub const fn nitro_sticker_packs(&self) -> GetNitroStickerPacks<'_> {
2578 GetNitroStickerPacks::new(self)
2579 }
2580
2581 /// Get information about a sticker pack and its stickers.
2582 pub const fn sticker_pack(&self, sticker_pack_id: Id<StickerPackMarker>) -> GetStickerPack<'_> {
2583 GetStickerPack::new(self, sticker_pack_id)
2584 }
2585
2586 /// Returns a list of stickers in a guild.
2587 ///
2588 /// # Examples
2589 ///
2590 /// ```no_run
2591 /// use twilight_http::Client;
2592 /// use twilight_model::id::Id;
2593 ///
2594 /// # #[tokio::main]
2595 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
2596 /// let client = Client::new("my token".to_owned());
2597 ///
2598 /// let guild_id = Id::new(1);
2599 /// let stickers = client.guild_stickers(guild_id).await?.models().await?;
2600 ///
2601 /// println!("{}", stickers.len());
2602 /// # Ok(()) }
2603 /// ```
2604 pub const fn guild_stickers(&self, guild_id: Id<GuildMarker>) -> GetGuildStickers<'_> {
2605 GetGuildStickers::new(self, guild_id)
2606 }
2607
2608 /// Returns a guild sticker by the guild's ID and the sticker's ID.
2609 ///
2610 /// # Examples
2611 ///
2612 /// ```no_run
2613 /// use twilight_http::Client;
2614 /// use twilight_model::id::Id;
2615 ///
2616 /// # #[tokio::main]
2617 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
2618 /// let client = Client::new("my token".to_owned());
2619 ///
2620 /// let guild_id = Id::new(1);
2621 /// let sticker_id = Id::new(2);
2622 /// let sticker = client
2623 /// .guild_sticker(guild_id, sticker_id)
2624 /// .await?
2625 /// .model()
2626 /// .await?;
2627 ///
2628 /// println!("{sticker:#?}");
2629 /// # Ok(()) }
2630 /// ```
2631 pub const fn guild_sticker(
2632 &self,
2633 guild_id: Id<GuildMarker>,
2634 sticker_id: Id<StickerMarker>,
2635 ) -> GetGuildSticker<'_> {
2636 GetGuildSticker::new(self, guild_id, sticker_id)
2637 }
2638
2639 /// Creates a sticker in a guild, and returns the created sticker.
2640 ///
2641 /// # Examples
2642 ///
2643 /// ```no_run
2644 /// use twilight_http::Client;
2645 /// use twilight_model::id::Id;
2646 ///
2647 /// # #[tokio::main]
2648 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
2649 /// let client = Client::new("my token".to_owned());
2650 ///
2651 /// let guild_id = Id::new(1);
2652 /// let sticker = client
2653 /// .create_guild_sticker(
2654 /// guild_id,
2655 /// &"sticker name",
2656 /// &"sticker description",
2657 /// &"sticker,tags",
2658 /// &[23, 23, 23, 23],
2659 /// )
2660 /// .await?
2661 /// .model()
2662 /// .await?;
2663 ///
2664 /// println!("{sticker:#?}");
2665 /// # Ok(()) }
2666 /// ```
2667 ///
2668 /// # Errors
2669 ///
2670 /// Returns an error of type [`DescriptionInvalid`] if the length is invalid.
2671 ///
2672 /// Returns an error of type [`NameInvalid`] if the length is invalid.
2673 ///
2674 /// Returns an error of type [`TagsInvalid`] if the length is invalid.
2675 ///
2676 /// [`DescriptionInvalid`]: twilight_validate::sticker::StickerValidationErrorType::DescriptionInvalid
2677 /// [`NameInvalid`]: twilight_validate::sticker::StickerValidationErrorType::NameInvalid
2678 /// [`TagsInvalid`]: twilight_validate::sticker::StickerValidationErrorType::TagsInvalid
2679 pub fn create_guild_sticker<'a>(
2680 &'a self,
2681 guild_id: Id<GuildMarker>,
2682 name: &'a str,
2683 description: &'a str,
2684 tags: &'a str,
2685 file: &'a [u8],
2686 ) -> CreateGuildSticker<'a> {
2687 CreateGuildSticker::new(self, guild_id, name, description, tags, file)
2688 }
2689
2690 /// Updates a sticker in a guild, and returns the updated sticker.
2691 ///
2692 /// # Examples
2693 ///
2694 /// ```no_run
2695 /// use twilight_http::Client;
2696 /// use twilight_model::id::Id;
2697 ///
2698 /// # #[tokio::main]
2699 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
2700 /// let client = Client::new("my token".to_owned());
2701 ///
2702 /// let guild_id = Id::new(1);
2703 /// let sticker_id = Id::new(2);
2704 /// let sticker = client
2705 /// .update_guild_sticker(guild_id, sticker_id)
2706 /// .description("new description")
2707 /// .await?
2708 /// .model()
2709 /// .await?;
2710 ///
2711 /// println!("{sticker:#?}");
2712 /// # Ok(()) }
2713 /// ```
2714 pub const fn update_guild_sticker(
2715 &self,
2716 guild_id: Id<GuildMarker>,
2717 sticker_id: Id<StickerMarker>,
2718 ) -> UpdateGuildSticker<'_> {
2719 UpdateGuildSticker::new(self, guild_id, sticker_id)
2720 }
2721
2722 /// Deletes a guild sticker by the ID of the guild and its ID.
2723 ///
2724 /// # Examples
2725 ///
2726 /// ```no_run
2727 /// use twilight_http::Client;
2728 /// use twilight_model::id::Id;
2729 ///
2730 /// # #[tokio::main]
2731 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
2732 /// let client = Client::new("my token".to_owned());
2733 ///
2734 /// let guild_id = Id::new(1);
2735 /// let sticker_id = Id::new(2);
2736 ///
2737 /// client.delete_guild_sticker(guild_id, sticker_id).await?;
2738 /// # Ok(()) }
2739 /// ```
2740 pub const fn delete_guild_sticker(
2741 &self,
2742 guild_id: Id<GuildMarker>,
2743 sticker_id: Id<StickerMarker>,
2744 ) -> DeleteGuildSticker<'_> {
2745 DeleteGuildSticker::new(self, guild_id, sticker_id)
2746 }
2747
2748 /// Creates a test entitlement to a given SKU for a given guild or user. Discord
2749 /// will act as though that user or guild has entitlement to your premium offering.
2750 ///
2751 /// # Examples
2752 ///
2753 /// ```no_run
2754 /// use twilight_http::{Client, request::application::monetization::CreateTestEntitlementOwner};
2755 /// use twilight_model::id::Id;
2756 ///
2757 /// # #[tokio::main]
2758 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
2759 /// let client = Client::new("my token".to_owned());
2760 ///
2761 /// let application_id = Id::new(1);
2762 /// let sku_id = Id::new(2);
2763 /// let owner = CreateTestEntitlementOwner::Guild(Id::new(3));
2764 ///
2765 /// client.create_test_entitlement(
2766 /// application_id,
2767 /// sku_id,
2768 /// owner,
2769 /// ).await?;
2770 ///
2771 /// # Ok(()) }
2772 pub const fn create_test_entitlement(
2773 &self,
2774 application_id: Id<ApplicationMarker>,
2775 sku_id: Id<SkuMarker>,
2776 owner: CreateTestEntitlementOwner,
2777 ) -> CreateTestEntitlement<'_> {
2778 CreateTestEntitlement::new(self, application_id, sku_id, owner)
2779 }
2780
2781 /// For One-Time Purchase consumable SKUs, marks a given entitlement for the
2782 /// user as consumed.
2783 ///
2784 /// The entitlement will have `consumed` as true when listing entitlements.
2785 pub const fn consume_entitlement(
2786 &self,
2787 application_id: Id<ApplicationMarker>,
2788 entitlement_id: Id<EntitlementMarker>,
2789 ) -> ConsumeEntitlement<'_> {
2790 ConsumeEntitlement::new(self, application_id, entitlement_id)
2791 }
2792
2793 /// Ends a poll in a channel.
2794 ///
2795 /// # Examples
2796 ///
2797 /// ```no_run
2798 /// use twilight_http::Client;
2799 /// use twilight_model::id::Id;
2800 ///
2801 /// # #[tokio::main]
2802 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
2803 /// let client = Client::new("my token".to_owned());
2804 ///
2805 /// let channel_id = Id::new(1);
2806 /// let message_id = Id::new(2);
2807 ///
2808 /// client.end_poll(channel_id, message_id).await?;
2809 /// # Ok(()) }
2810 /// ```
2811 pub const fn end_poll(
2812 &self,
2813 channel_id: Id<ChannelMarker>,
2814 message_id: Id<MessageMarker>,
2815 ) -> EndPoll<'_> {
2816 EndPoll::new(self, channel_id, message_id)
2817 }
2818
2819 /// Deletes a currently-active test entitlement. Discord will act as though that user or
2820 /// guild no longer has entitlement to your premium offering.
2821 ///
2822 /// # Examples
2823 ///
2824 /// ```no_run
2825 /// use twilight_http::Client;
2826 /// use twilight_model::id::Id;
2827 ///
2828 /// # #[tokio::main]
2829 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
2830 /// let client = Client::new("my token".to_owned());
2831 ///
2832 /// let application_id = Id::new(1);
2833 /// let entitlement_id = Id::new(2);
2834 ///
2835 /// client.delete_test_entitlement(
2836 /// application_id,
2837 /// entitlement_id,
2838 /// ).await?;
2839 ///
2840 /// # Ok(()) }
2841 pub const fn delete_test_entitlement(
2842 &self,
2843 application_id: Id<ApplicationMarker>,
2844 entitlement_id: Id<EntitlementMarker>,
2845 ) -> DeleteTestEntitlement<'_> {
2846 DeleteTestEntitlement::new(self, application_id, entitlement_id)
2847 }
2848
2849 /// /// Get the voters for an answer in a poll.
2850 ///
2851 /// # Examples
2852 ///
2853 /// ```no_run
2854 /// use twilight_http::Client;
2855 /// use twilight_model::id::Id;
2856 ///
2857 /// # #[tokio::main]
2858 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
2859 /// let client = Client::new("my token".to_owned());
2860 ///
2861 /// let channel_id = Id::new(1);
2862 /// let message_id = Id::new(2);
2863 /// let answer_id = 1;
2864 ///
2865 /// let voters = client.get_answer_voters(channel_id, message_id, answer_id).await?;
2866 ///
2867 /// println!("{:?}", voters);
2868 /// # Ok(()) }
2869 pub const fn get_answer_voters(
2870 &self,
2871 channel_id: Id<ChannelMarker>,
2872 message_id: Id<MessageMarker>,
2873 answer_id: u8,
2874 ) -> GetAnswerVoters<'_> {
2875 GetAnswerVoters::new(self, channel_id, message_id, answer_id)
2876 }
2877
2878 /// Returns all SKUs for a given application.
2879 ///
2880 /// # Examples
2881 ///
2882 /// ```no_run
2883 /// use twilight_http::Client;
2884 /// use twilight_model::id::Id;
2885 ///
2886 /// # #[tokio::main]
2887 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
2888 /// let client = Client::new("my token".to_owned());
2889 ///
2890 /// let application_id = Id::new(1);
2891 ///
2892 /// let skus = client.get_skus(application_id).await?;
2893 ///
2894 /// # Ok(()) }
2895 pub const fn get_skus(&self, application_id: Id<ApplicationMarker>) -> GetSKUs<'_> {
2896 GetSKUs::new(self, application_id)
2897 }
2898
2899 /// Returns all subscriptions containing the SKU, filtered by user.
2900 pub const fn get_sku_subscriptions(&self, sku_id: Id<SkuMarker>) -> GetSKUSubscriptions<'_> {
2901 GetSKUSubscriptions::new(self, sku_id)
2902 }
2903
2904 /// Get a subscription by SKU ID and Subscription ID.
2905 pub const fn get_sku_subscription(
2906 &self,
2907 sku_id: Id<SkuMarker>,
2908 subscription_id: Id<SubscriptionMarker>,
2909 ) -> GetSKUSubscription<'_> {
2910 GetSKUSubscription::new(self, sku_id, subscription_id)
2911 }
2912
2913 /// Gets all emojis associated with an application
2914 ///
2915 /// # Examples
2916 ///
2917 /// ```no_run
2918 /// use twilight_http::Client;
2919 /// use twilight_model::id::Id;
2920 ///
2921 /// # #[tokio::main]
2922 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
2923 /// let client = Client::new("my token".to_owned());
2924 ///
2925 /// let application_id = Id::new(1);
2926 ///
2927 /// let emojis = client.get_application_emojis(application_id).await?;
2928 ///
2929 /// # Ok(()) }
2930 /// ```
2931 pub const fn get_application_emojis(
2932 &self,
2933 application_id: Id<ApplicationMarker>,
2934 ) -> ListApplicationEmojis<'_> {
2935 ListApplicationEmojis::new(self, application_id)
2936 }
2937
2938 /// Adds an emoji to an application
2939 ///
2940 /// Needs to be base64 encoded and prefixed and tagged.
2941 /// Can be up to 128x128 in size
2942 ///
2943 /// # Examples
2944 ///
2945 /// ```no_run
2946 /// use twilight_http::Client;
2947 /// use twilight_model::id::Id;
2948 ///
2949 /// # #[tokio::main]
2950 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
2951 /// let client = Client::new("my token".to_owned());
2952 ///
2953 /// let application_id = Id::new(1);
2954 ///
2955 /// client
2956 /// .add_application_emoji(application_id, "name", "data:image/png;base64,image_data")
2957 /// .await?;
2958 ///
2959 /// # Ok(()) }
2960 /// ```
2961 pub const fn add_application_emoji<'a>(
2962 &'a self,
2963 application_id: Id<ApplicationMarker>,
2964 name: &'a str,
2965 image: &'a str,
2966 ) -> AddApplicationEmoji<'a> {
2967 AddApplicationEmoji::new(self, application_id, name, image)
2968 }
2969
2970 /// Updates an emoji associated with an application.
2971 ///
2972 /// # Examples
2973 ///
2974 /// ```no_run
2975 /// use twilight_http::Client;
2976 /// use twilight_model::id::Id;
2977 ///
2978 /// # #[tokio::main]
2979 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
2980 /// let client = Client::new("my token".to_owned());
2981 ///
2982 /// let application_id = Id::new(1);
2983 /// let emoji_id = Id::new(2);
2984 ///
2985 /// client
2986 /// .update_application_emoji(application_id, emoji_id, "new emoji name")
2987 /// .await?;
2988 ///
2989 /// # Ok(()) }
2990 /// ```
2991 pub const fn update_application_emoji<'a>(
2992 &'a self,
2993 application_id: Id<ApplicationMarker>,
2994 emoji_id: Id<EmojiMarker>,
2995 name: &'a str,
2996 ) -> UpdateApplicationEmoji<'a> {
2997 UpdateApplicationEmoji::new(self, application_id, emoji_id, name)
2998 }
2999
3000 /// Deletes an emoji associated with an application.
3001 ///
3002 /// # Examples
3003 ///
3004 /// ```no_run
3005 /// use twilight_http::Client;
3006 /// use twilight_model::id::Id;
3007 ///
3008 /// # #[tokio::main]
3009 /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
3010 /// let client = Client::new("my token".to_owned());
3011 ///
3012 /// let application_id = Id::new(1);
3013 /// let emoji_id = Id::new(2);
3014 ///
3015 /// client
3016 /// .delete_application_emoji(application_id, emoji_id)
3017 /// .await?;
3018 ///
3019 /// # Ok(()) }
3020 /// ```
3021 pub const fn delete_application_emoji(
3022 &self,
3023 application_id: Id<ApplicationMarker>,
3024 emoji_id: Id<EmojiMarker>,
3025 ) -> DeleteApplicationEmoji<'_> {
3026 DeleteApplicationEmoji::new(self, application_id, emoji_id)
3027 }
3028
3029 /// Execute a request, returning a future resolving to a [`Response`].
3030 ///
3031 /// # Errors
3032 ///
3033 /// Returns an [`ErrorType::Unauthorized`] error type if the configured
3034 /// token has become invalid due to expiration, revocation, etc.
3035 ///
3036 /// [`Response`]: super::response::Response
3037 pub fn request<T>(&self, request: Request) -> ResponseFuture<T> {
3038 match self.try_request::<T>(request) {
3039 Ok(future) => future,
3040 Err(source) => ResponseFuture::error(source),
3041 }
3042 }
3043
3044 fn try_request<T>(&self, request: Request) -> Result<ResponseFuture<T>, Error> {
3045 if let Some(token_invalidated) = self.token_invalidated.as_ref()
3046 && token_invalidated.load(Ordering::Relaxed)
3047 {
3048 return Err(Error {
3049 kind: ErrorType::Unauthorized,
3050 source: None,
3051 });
3052 }
3053
3054 let Request {
3055 body,
3056 form,
3057 headers: req_headers,
3058 method,
3059 mut path,
3060 use_authorization_token,
3061 } = request;
3062
3063 let protocol = if self.use_http { "http" } else { "https" };
3064 let host = self.proxy.as_deref().unwrap_or("discord.com");
3065
3066 let url = format!("{protocol}://{host}/api/v{API_VERSION}/{path}");
3067
3068 let mut builder = hyper::Request::builder().method(method.name()).uri(&url);
3069
3070 if use_authorization_token && let Some(token) = self.token.as_deref() {
3071 let value = HeaderValue::from_str(token).map_err(|source| {
3072 let name = AUTHORIZATION.to_string();
3073
3074 Error {
3075 kind: ErrorType::CreatingHeader { name },
3076 source: Some(Box::new(source)),
3077 }
3078 })?;
3079
3080 if let Some(headers) = builder.headers_mut() {
3081 headers.insert(AUTHORIZATION, value);
3082 }
3083 }
3084
3085 if let Some(headers) = builder.headers_mut() {
3086 if let Some(form) = &form {
3087 headers.insert(CONTENT_LENGTH, HeaderValue::from(form.len()));
3088 if let Ok(content_type) = HeaderValue::try_from(form.content_type()) {
3089 headers.insert(CONTENT_TYPE, content_type);
3090 }
3091 } else if let Some(bytes) = &body {
3092 headers.insert(CONTENT_LENGTH, HeaderValue::from(bytes.len()));
3093 headers.insert(CONTENT_TYPE, HeaderValue::from_static("application/json"));
3094 } else if matches!(method, Method::Put | Method::Post | Method::Patch) {
3095 headers.insert(CONTENT_LENGTH, HeaderValue::from(0));
3096 }
3097
3098 #[cfg(feature = "decompression")]
3099 headers.insert(
3100 hyper::header::ACCEPT_ENCODING,
3101 HeaderValue::from_static("br"),
3102 );
3103
3104 headers.insert(USER_AGENT, HeaderValue::from_static(TWILIGHT_USER_AGENT));
3105
3106 if let Some(req_headers) = req_headers {
3107 for (maybe_name, value) in req_headers {
3108 if let Some(name) = maybe_name {
3109 headers.insert(name, value);
3110 }
3111 }
3112 }
3113
3114 if let Some(default_headers) = &self.default_headers {
3115 for (name, value) in default_headers {
3116 headers.insert(name, value.clone());
3117 }
3118 }
3119 }
3120
3121 let try_req = if let Some(form) = form {
3122 builder.body(Full::from(form.build()))
3123 } else if let Some(bytes) = body {
3124 builder.body(Full::from(bytes))
3125 } else {
3126 builder.body(Full::default())
3127 };
3128
3129 let http_request = try_req.map_err(|source| Error {
3130 kind: ErrorType::BuildingRequest,
3131 source: Some(Box::new(source)),
3132 })?;
3133
3134 // For requests that don't use an authorization token we don't need to
3135 // remember whether the token is invalid. This may be for requests such
3136 // as webhooks and interactions.
3137 let invalid_token = use_authorization_token
3138 .then(|| self.token_invalidated.clone())
3139 .flatten();
3140
3141 if let Some(i) = path.find('?') {
3142 path.truncate(i);
3143 }
3144 let response = ResponseFuture::new(
3145 self.http.clone(),
3146 invalid_token,
3147 http_request,
3148 tracing::info_span!("request", method = method.name(), path),
3149 self.timeout,
3150 self.ratelimiter.clone(),
3151 Endpoint { method, path },
3152 );
3153
3154 Ok(response)
3155 }
3156}
3157
3158#[cfg(test)]
3159mod tests {
3160 use super::Client;
3161
3162 #[test]
3163 fn client_debug_with_token() {
3164 assert!(
3165 format!("{:?}", Client::new("Bot foo".to_owned())).contains("token: Some(<redacted>)")
3166 );
3167 assert!(format!("{:?}", Client::builder().build()).contains("token: None"));
3168 }
3169}