HttpClient

Struct HttpClient 

Source
pub struct HttpClient { /* private fields */ }
Expand description

Discord REST API client.

Handles all HTTP communication with Discord, including:

  • Authentication (Bot token)
  • Rate limit tracking and waiting
  • JSON serialization/deserialization
  • Error handling

§Thread Safety

HttpClient can be cloned and shared across tasks. The inner reqwest::Client uses connection pooling internally.

Implementations§

Source§

impl HttpClient

Source

pub async fn list_auto_moderation_rules( &self, guild_id: Snowflake, ) -> Result<Vec<AutoModRule>, HttpError>

List Auto Moderation rules.

Source

pub async fn get_auto_moderation_rule( &self, guild_id: Snowflake, rule_id: Snowflake, ) -> Result<AutoModRule, HttpError>

Get an Auto Moderation rule.

Source

pub async fn create_auto_moderation_rule( &self, guild_id: Snowflake, params: &CreateAutoModRuleParams, ) -> Result<AutoModRule, HttpError>

Create an Auto Moderation rule.

Source

pub async fn modify_auto_moderation_rule( &self, guild_id: Snowflake, rule_id: Snowflake, params: &ModifyAutoModRuleParams, ) -> Result<AutoModRule, HttpError>

Modify an Auto Moderation rule.

Source

pub async fn delete_auto_moderation_rule( &self, guild_id: Snowflake, rule_id: Snowflake, ) -> Result<(), HttpError>

Delete an Auto Moderation rule.

Source§

impl HttpClient

Source

pub async fn get_channel( &self, channel_id: Snowflake, ) -> Result<Channel<'static>, HttpError>

Get a channel.

Source

pub async fn delete_channel( &self, channel_id: Snowflake, reason: Option<&str>, ) -> Result<Channel<'static>, HttpError>

Delete/Close a channel.

Source

pub async fn create_channel( &self, guild_id: Snowflake, params: &CreateChannel<'_>, ) -> Result<Channel<'static>, HttpError>

Create a new channel in a guild.

Source

pub async fn get_message( &self, channel_id: Snowflake, message_id: Snowflake, ) -> Result<Message<'static>, HttpError>

Get a single message.

Source

pub async fn create_message_struct( &self, channel_id: Snowflake, message: &CreateMessage<'_>, ) -> Result<Message<'static>, HttpError>

Send a message to a channel.

Source

pub async fn send_message( &self, channel_id: Snowflake, content: impl Into<String>, ) -> Result<Message<'static>, HttpError>

Send a simple text message.

Source

pub async fn edit_message( &self, channel_id: Snowflake, message_id: Snowflake, content: impl Into<String>, ) -> Result<Message<'static>, HttpError>

Edit a message.

Source

pub async fn delete_message( &self, channel_id: Snowflake, message_id: Snowflake, reason: Option<&str>, ) -> Result<(), HttpError>

Delete a message.

Source

pub async fn bulk_delete_messages( &self, channel_id: Snowflake, message_ids: &[Snowflake], ) -> Result<(), HttpError>

Bulk delete messages (2-100 messages, not older than 14 days). This is much faster than deleting one by one.

Source

pub async fn create_webhook( &self, channel_id: Snowflake, name: &str, avatar: Option<&str>, ) -> Result<Webhook<'static>, HttpError>

Create a webhook.

Source

pub async fn get_channel_webhooks( &self, channel_id: Snowflake, ) -> Result<Vec<Webhook<'static>>, HttpError>

Get channel webhooks.

Source

pub async fn get_guild_webhooks( &self, guild_id: Snowflake, ) -> Result<Vec<Webhook<'static>>, HttpError>

Get guild webhooks.

Source

pub async fn execute_webhook( &self, webhook_id: Snowflake, webhook_token: &str, params: &ExecuteWebhook, ) -> Result<Option<Message<'static>>, HttpError>

Execute webhook (send message).

Source§

impl HttpClient

Source

pub fn new(token: impl Into<String>) -> Result<Self, HttpError>

Create a new HTTP client with the given bot token.

Source

pub fn token(&self) -> &str

Get the bot token.

Source

pub async fn get_gateway_bot(&self) -> Result<GatewayBotResponse, HttpError>

Get gateway bot information.

Returns the recommended number of shards, gateway URL, and session limits. This is essential for large bots to determine sharding configuration.

Source

pub async fn get_current_user(&self) -> Result<CurrentUser, HttpError>

Get the current bot user.

Source

pub async fn get_current_application( &self, ) -> Result<CurrentApplication, HttpError>

Get the current application.

Source

pub async fn create_global_application_command( &self, application_id: Snowflake, command: &ApplicationCommand, ) -> Result<ApplicationCommand, HttpError>

Create a global application command.

Source

pub async fn create_message( &self, channel_id: Snowflake, content: &CreateMessage<'_>, ) -> Result<Message<'static>, HttpError>

Create a message in a channel.

Source§

impl HttpClient

Source

pub async fn list_guild_emojis( &self, guild_id: Snowflake, ) -> Result<Vec<Emoji<'static>>, HttpError>

List guild emojis.

Source

pub async fn get_guild_emoji( &self, guild_id: Snowflake, emoji_id: Snowflake, ) -> Result<Emoji<'static>, HttpError>

Get guild emoji.

Source

pub async fn create_guild_emoji( &self, guild_id: Snowflake, params: &CreateEmojiParams, ) -> Result<Emoji<'static>, HttpError>

Create guild emoji.

Source

pub async fn modify_guild_emoji( &self, guild_id: Snowflake, emoji_id: Snowflake, params: &ModifyEmojiParams, ) -> Result<Emoji<'static>, HttpError>

Modify guild emoji.

Source

pub async fn delete_guild_emoji( &self, guild_id: Snowflake, emoji_id: Snowflake, ) -> Result<(), HttpError>

Delete guild emoji.

Source

pub async fn list_guild_stickers( &self, guild_id: Snowflake, ) -> Result<Vec<Sticker<'static>>, HttpError>

List guild stickers.

Source

pub async fn get_guild_sticker( &self, guild_id: Snowflake, sticker_id: Snowflake, ) -> Result<Sticker<'static>, HttpError>

Get guild sticker.

Source

pub async fn create_guild_sticker( &self, guild_id: Snowflake, params: &CreateStickerParams, ) -> Result<Sticker<'static>, HttpError>

Create guild sticker.

Source

pub async fn delete_guild_sticker( &self, guild_id: Snowflake, sticker_id: Snowflake, ) -> Result<(), HttpError>

Delete guild sticker.

Source§

impl HttpClient

Source

pub async fn get_member( &self, guild_id: Snowflake, user_id: Snowflake, ) -> Result<GuildMember<'static>, HttpError>

Get a guild member.

Source

pub async fn list_members( &self, guild_id: Snowflake, limit: Option<u32>, after: Option<Snowflake>, ) -> Result<Vec<GuildMember<'static>>, HttpError>

List guild members.

Source

pub async fn kick_member( &self, guild_id: Snowflake, user_id: Snowflake, reason: Option<&str>, ) -> Result<(), HttpError>

Kick a member from the guild.

Source

pub async fn ban_member( &self, guild_id: Snowflake, user_id: Snowflake, delete_message_seconds: Option<u32>, reason: Option<&str>, ) -> Result<(), HttpError>

Ban a member from the guild.

Source

pub async fn unban_member( &self, guild_id: Snowflake, user_id: Snowflake, reason: Option<&str>, ) -> Result<(), HttpError>

Unban a member.

Source

pub async fn modify_member( &self, guild_id: Snowflake, user_id: Snowflake, params: &ModifyMember<'_>, ) -> Result<GuildMember<'static>, HttpError>

Modify a guild member.

Source

pub async fn get_roles( &self, guild_id: Snowflake, ) -> Result<Vec<Role<'static>>, HttpError>

Get all roles.

Source

pub async fn create_role( &self, guild_id: Snowflake, params: &CreateRole<'_>, ) -> Result<Role<'static>, HttpError>

Create a new role.

Source

pub async fn delete_role( &self, guild_id: Snowflake, role_id: Snowflake, reason: Option<&str>, ) -> Result<(), HttpError>

Delete a role.

Source

pub async fn get_guild_audit_log( &self, guild_id: Snowflake, params: &GetAuditLogParams, ) -> Result<AuditLog<'static>, HttpError>

Get guild audit log.

Source

pub async fn list_guild_soundboard_sounds( &self, guild_id: Snowflake, ) -> Result<Vec<SoundboardSound<'static>>, HttpError>

List soundboard sounds for a guild.

Source

pub async fn get_guild_soundboard_sound( &self, guild_id: Snowflake, sound_id: Snowflake, ) -> Result<SoundboardSound<'static>, HttpError>

Get a specific soundboard sound.

Source

pub async fn create_guild_soundboard_sound( &self, guild_id: Snowflake, payload: &Value, ) -> Result<SoundboardSound<'static>, HttpError>

Create a soundboard sound.

Source

pub async fn modify_guild_soundboard_sound( &self, guild_id: Snowflake, sound_id: Snowflake, payload: &Value, ) -> Result<SoundboardSound<'static>, HttpError>

Modify a soundboard sound.

Source

pub async fn delete_guild_soundboard_sound( &self, guild_id: Snowflake, sound_id: Snowflake, ) -> Result<(), HttpError>

Delete a soundboard sound.

Source§

impl HttpClient

Source

pub async fn create_interaction_response( &self, interaction_id: Snowflake, token: &str, response: &InteractionResponse<'_>, ) -> Result<(), HttpError>

Create a response to an Interaction.

This is the initial response to an interaction (Slash Command, Button, etc.). You must respond within 3 seconds, or use InteractionCallbackType::DeferredChannelMessageWithSource.

Source

pub async fn get_original_interaction_response( &self, application_id: Snowflake, token: &str, ) -> Result<Message<'static>, HttpError>

Get the original response message.

Source

pub async fn edit_original_interaction_response<B: Serialize>( &self, application_id: Snowflake, token: &str, body: B, ) -> Result<Message<'static>, HttpError>

Edit the original response message.

This is used to update the message after a DEFER response.

Source

pub async fn delete_original_interaction_response( &self, application_id: Snowflake, token: &str, ) -> Result<(), HttpError>

Delete the original response message.

Source

pub async fn create_followup_message<B: Serialize>( &self, application_id: Snowflake, token: &str, body: B, ) -> Result<Message<'static>, HttpError>

Create a followup message.

Used to send additional messages after the initial response.

Source§

impl HttpClient

Source

pub async fn list_skus( &self, application_id: Snowflake, ) -> Result<Vec<Sku>, HttpError>

List SKUs for an application.

Source

pub async fn list_entitlements( &self, application_id: Snowflake, query: Option<&Value>, ) -> Result<Vec<Entitlement>, HttpError>

List entitlements for an application.

Source

pub async fn get_entitlement( &self, application_id: Snowflake, entitlement_id: Snowflake, ) -> Result<Entitlement, HttpError>

Get an entitlement.

Source

pub async fn create_test_entitlement( &self, application_id: Snowflake, payload: &Value, ) -> Result<Entitlement, HttpError>

Create a test entitlement.

Source

pub async fn delete_test_entitlement( &self, application_id: Snowflake, entitlement_id: Snowflake, ) -> Result<(), HttpError>

Delete a test entitlement.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more