pub struct Http {
pub ratelimiter: Ratelimiter,
pub ratelimiter_disabled: bool,
pub proxy: Option<Url>,
pub token: String,
/* private fields */
}
http
only.Expand description
Note: For all member functions that return a Result
, the
Error kind will be either Error::Http
or Error::Json
.
Fields
ratelimiter: Ratelimiter
ratelimiter_disabled: bool
proxy: Option<Url>
token: String
Implementations
sourceimpl Http
impl Http
pub fn new(token: &str) -> Self
pub fn new_with_application_id(token: &str, application_id: u64) -> Self
pub fn application_id(&self) -> Option<u64>
pub fn set_application_id(&self, application_id: u64)
sourcepub async fn add_guild_member(
&self,
guild_id: u64,
user_id: u64,
map: &JsonMap
) -> Result<Option<Member>>
pub async fn add_guild_member(
&self,
guild_id: u64,
user_id: u64,
map: &JsonMap
) -> Result<Option<Member>>
sourcepub async fn add_member_role(
&self,
guild_id: u64,
user_id: u64,
role_id: u64,
audit_log_reason: Option<&str>
) -> Result<()>
pub async fn add_member_role(
&self,
guild_id: u64,
user_id: u64,
role_id: u64,
audit_log_reason: Option<&str>
) -> Result<()>
Adds a single Role
to a Member
in a Guild
.
Note: Requires the Manage Roles permission and respect of role hierarchy.
sourcepub async fn ban_user(
&self,
guild_id: u64,
user_id: u64,
delete_message_days: u8,
reason: &str
) -> Result<()>
pub async fn ban_user(
&self,
guild_id: u64,
user_id: u64,
delete_message_days: u8,
reason: &str
) -> Result<()>
Bans a User
from a Guild
, removing their messages sent in the last
X number of days.
Passing a delete_message_days
of 0
is equivalent to not removing any
messages. Up to 7
days’ worth of messages may be deleted.
Note: Requires that you have the Ban Members permission.
sourcepub async fn broadcast_typing(&self, channel_id: u64) -> Result<()>
pub async fn broadcast_typing(&self, channel_id: u64) -> Result<()>
Broadcasts that the current user is typing in the given Channel
.
This lasts for about 10 seconds, and will then need to be renewed to indicate that the current user is still typing.
This should rarely be used for bots, although it is a good indicator that a long-running command is still being processed.
sourcepub async fn create_channel(
&self,
guild_id: u64,
map: &JsonMap,
audit_log_reason: Option<&str>
) -> Result<GuildChannel>
pub async fn create_channel(
&self,
guild_id: u64,
map: &JsonMap,
audit_log_reason: Option<&str>
) -> Result<GuildChannel>
Creates a GuildChannel
in the Guild
given its Id.
Refer to the Discord’s docs for information on what fields this requires.
Note: Requires the Manage Channels permission.
sourcepub async fn create_stage_instance(&self, map: &Value) -> Result<StageInstance>
pub async fn create_stage_instance(&self, map: &Value) -> Result<StageInstance>
Creates a stage instance.
sourcepub async fn create_public_thread(
&self,
channel_id: u64,
message_id: u64,
map: &JsonMap
) -> Result<GuildChannel>
pub async fn create_public_thread(
&self,
channel_id: u64,
message_id: u64,
map: &JsonMap
) -> Result<GuildChannel>
Creates a public thread channel in the GuildChannel
given its Id,
with a base message Id.
sourcepub async fn create_private_thread(
&self,
channel_id: u64,
map: &JsonMap
) -> Result<GuildChannel>
pub async fn create_private_thread(
&self,
channel_id: u64,
map: &JsonMap
) -> Result<GuildChannel>
Creates a private thread channel in the GuildChannel
given its Id.
sourcepub async fn create_emoji(
&self,
guild_id: u64,
map: &Value,
audit_log_reason: Option<&str>
) -> Result<Emoji>
pub async fn create_emoji(
&self,
guild_id: u64,
map: &Value,
audit_log_reason: Option<&str>
) -> Result<Emoji>
Creates an emoji in the given Guild
with the given data.
View the source code for Guild::create_emoji
method to see what
fields this requires.
Note: Requires the Manage Emojis and Stickers permission.
sourcepub async fn create_followup_message(
&self,
interaction_token: &str,
map: &Value
) -> Result<Message>
pub async fn create_followup_message(
&self,
interaction_token: &str,
map: &Value
) -> Result<Message>
Create a follow-up message for an Interaction.
Functions the same as Self::execute_webhook
sourcepub async fn create_followup_message_with_files(
&self,
interaction_token: &str,
map: &Value,
files: impl IntoIterator<Item = AttachmentType<'_>>
) -> Result<Message>
pub async fn create_followup_message_with_files(
&self,
interaction_token: &str,
map: &Value,
files: impl IntoIterator<Item = AttachmentType<'_>>
) -> Result<Message>
Create a follow-up message with attachments for an Interaction.
Functions the same as Self::execute_webhook
sourcepub async fn create_global_application_command(
&self,
map: &Value
) -> Result<Command>
pub async fn create_global_application_command(
&self,
map: &Value
) -> Result<Command>
Creates a new global command.
New global commands will be available in all guilds after 1 hour.
Refer to Discord’s docs for field information.
Note: Creating a command with the same name as an existing command for your application will overwrite the old command.
sourcepub async fn create_global_application_commands(
&self,
map: &Value
) -> Result<Vec<Command>>
pub async fn create_global_application_commands(
&self,
map: &Value
) -> Result<Vec<Command>>
Creates new global application commands.
sourcepub async fn create_guild_application_commands(
&self,
guild_id: u64,
map: &Value
) -> Result<Vec<Command>>
pub async fn create_guild_application_commands(
&self,
guild_id: u64,
map: &Value
) -> Result<Vec<Command>>
Creates new guild application commands.
sourcepub async fn create_guild(&self, map: &Value) -> Result<PartialGuild>
pub async fn create_guild(&self, map: &Value) -> Result<PartialGuild>
Creates a guild with the data provided.
Only a PartialGuild
will be immediately returned, and a full Guild
will be received over a Shard
, if at least one is running.
Note: This endpoint is currently limited to 10 active guilds. The limits are raised for whitelisted GameBridge applications. See the documentation on this endpoint for more info.
Examples
Create a guild called "test"
in the [US West region]:
use serenity::http::Http;
use serenity::json::json;
let map = json!({
"name": "test",
});
let _result = http.create_guild(&map).await?;
sourcepub async fn create_guild_application_command(
&self,
guild_id: u64,
map: &Value
) -> Result<Command>
pub async fn create_guild_application_command(
&self,
guild_id: u64,
map: &Value
) -> Result<Command>
Creates a new guild command.
New guild commands will be available in the guild immediately.
Refer to Discord’s docs for field information.
sourcepub async fn create_guild_integration(
&self,
guild_id: u64,
integration_id: u64,
map: &Value,
audit_log_reason: Option<&str>
) -> Result<()>
pub async fn create_guild_integration(
&self,
guild_id: u64,
integration_id: u64,
map: &Value,
audit_log_reason: Option<&str>
) -> Result<()>
Creates an Integration
for a Guild
.
Refer to Discord’s docs for field information.
Note: Requires the Manage Guild permission.
sourcepub async fn create_interaction_response(
&self,
interaction_id: u64,
interaction_token: &str,
map: &Value
) -> Result<()>
pub async fn create_interaction_response(
&self,
interaction_id: u64,
interaction_token: &str,
map: &Value
) -> Result<()>
Creates a response to an Interaction
from the gateway.
Refer to Discord’s docs for the object it takes.
sourcepub async fn create_interaction_response_with_files(
&self,
interaction_id: u64,
interaction_token: &str,
map: &Value,
files: impl IntoIterator<Item = AttachmentType<'_>>
) -> Result<()>
pub async fn create_interaction_response_with_files(
&self,
interaction_id: u64,
interaction_token: &str,
map: &Value,
files: impl IntoIterator<Item = AttachmentType<'_>>
) -> Result<()>
Creates a response to an Interaction
from the gateway with files.
Refer to Discord’s docs for the object it takes.
sourcepub async fn create_invite(
&self,
channel_id: u64,
map: &JsonMap,
audit_log_reason: Option<&str>
) -> Result<RichInvite>
pub async fn create_invite(
&self,
channel_id: u64,
map: &JsonMap,
audit_log_reason: Option<&str>
) -> Result<RichInvite>
Creates a RichInvite
for the given channel.
Refer to Discord’s docs for field information.
All fields are optional.
Note: Requires the Create Instant Invite permission.
sourcepub async fn create_permission(
&self,
channel_id: u64,
target_id: u64,
map: &Value
) -> Result<()>
pub async fn create_permission(
&self,
channel_id: u64,
target_id: u64,
map: &Value
) -> Result<()>
Creates a permission override for a member or a role in a channel.
sourcepub async fn create_private_channel(&self, map: &Value) -> Result<PrivateChannel>
pub async fn create_private_channel(&self, map: &Value) -> Result<PrivateChannel>
Creates a private channel with a user.
sourcepub async fn create_reaction(
&self,
channel_id: u64,
message_id: u64,
reaction_type: &ReactionType
) -> Result<()>
pub async fn create_reaction(
&self,
channel_id: u64,
message_id: u64,
reaction_type: &ReactionType
) -> Result<()>
Reacts to a message.
sourcepub async fn create_role(
&self,
guild_id: u64,
map: &JsonMap,
audit_log_reason: Option<&str>
) -> Result<Role>
pub async fn create_role(
&self,
guild_id: u64,
map: &JsonMap,
audit_log_reason: Option<&str>
) -> Result<Role>
Creates a role.
sourcepub async fn create_scheduled_event(
&self,
guild_id: u64,
map: &JsonMap,
audit_log_reason: Option<&str>
) -> Result<ScheduledEvent>
pub async fn create_scheduled_event(
&self,
guild_id: u64,
map: &JsonMap,
audit_log_reason: Option<&str>
) -> Result<ScheduledEvent>
Creates a Guild Scheduled Event.
Refer to Discord’s docs for field information.
Note: Requires the Manage Events permission.
sourcepub async fn create_sticker<'a>(
&self,
guild_id: u64,
map: JsonMap,
file: impl Into<AttachmentType<'a>>,
audit_log_reason: Option<&str>
) -> Result<Sticker>
pub async fn create_sticker<'a>(
&self,
guild_id: u64,
map: JsonMap,
file: impl Into<AttachmentType<'a>>,
audit_log_reason: Option<&str>
) -> Result<Sticker>
Creates a sticker.
Note: Requires the Manage Emojis and Stickers permission.
sourcepub async fn create_webhook(
&self,
channel_id: u64,
map: &Value,
audit_log_reason: Option<&str>
) -> Result<Webhook>
pub async fn create_webhook(
&self,
channel_id: u64,
map: &Value,
audit_log_reason: Option<&str>
) -> Result<Webhook>
Creates a webhook for the given channel’s Id, passing in the given data.
This method requires authentication.
The Value is a map with the values of:
- avatar: base64-encoded 128x128 image for the webhook’s default avatar (optional);
- name: the name of the webhook, limited to between 2 and 100 characters long.
Examples
Creating a webhook named test
:
use serenity::http::Http;
use serenity::json::json;
let channel_id = 81384788765712384;
let map = json!({"name": "test"});
let webhook = http.create_webhook(channel_id, &map, None).await?;
sourcepub async fn delete_channel(&self, channel_id: u64) -> Result<Channel>
pub async fn delete_channel(&self, channel_id: u64) -> Result<Channel>
Deletes a private channel or a channel in a guild.
sourcepub async fn delete_stage_instance(&self, channel_id: u64) -> Result<()>
pub async fn delete_stage_instance(&self, channel_id: u64) -> Result<()>
Deletes a stage instance.
sourcepub async fn delete_emoji(&self, guild_id: u64, emoji_id: u64) -> Result<()>
pub async fn delete_emoji(&self, guild_id: u64, emoji_id: u64) -> Result<()>
Deletes an emoji from a server.
sourcepub async fn delete_followup_message(
&self,
interaction_token: &str,
message_id: u64
) -> Result<()>
pub async fn delete_followup_message(
&self,
interaction_token: &str,
message_id: u64
) -> Result<()>
Deletes a follow-up message for an interaction.
sourcepub async fn delete_global_application_command(
&self,
command_id: u64
) -> Result<()>
pub async fn delete_global_application_command(
&self,
command_id: u64
) -> Result<()>
Deletes a global command.
sourcepub async fn delete_guild(&self, guild_id: u64) -> Result<PartialGuild>
pub async fn delete_guild(&self, guild_id: u64) -> Result<PartialGuild>
Deletes a guild, only if connected account owns it.
sourcepub async fn delete_guild_application_command(
&self,
guild_id: u64,
command_id: u64
) -> Result<()>
pub async fn delete_guild_application_command(
&self,
guild_id: u64,
command_id: u64
) -> Result<()>
Deletes a guild command.
sourcepub async fn delete_guild_integration(
&self,
guild_id: u64,
integration_id: u64
) -> Result<()>
pub async fn delete_guild_integration(
&self,
guild_id: u64,
integration_id: u64
) -> Result<()>
Removes an integration from a guild.
sourcepub async fn delete_invite(&self, code: &str) -> Result<Invite>
pub async fn delete_invite(&self, code: &str) -> Result<Invite>
Deletes an invite by code.
sourcepub async fn delete_message(&self, channel_id: u64, message_id: u64) -> Result<()>
pub async fn delete_message(&self, channel_id: u64, message_id: u64) -> Result<()>
Deletes a message if created by us or we have specific permissions.
sourcepub async fn delete_messages(&self, channel_id: u64, map: &Value) -> Result<()>
pub async fn delete_messages(&self, channel_id: u64, map: &Value) -> Result<()>
Deletes a bunch of messages, only works for bots.
sourcepub async fn delete_message_reaction_emoji(
&self,
channel_id: u64,
message_id: u64,
reaction_type: &ReactionType
) -> Result<()>
pub async fn delete_message_reaction_emoji(
&self,
channel_id: u64,
message_id: u64,
reaction_type: &ReactionType
) -> Result<()>
Deletes all the reactions for a given emoji on a message.
sourcepub async fn delete_original_interaction_response(
&self,
interaction_token: &str
) -> Result<()>
pub async fn delete_original_interaction_response(
&self,
interaction_token: &str
) -> Result<()>
Deletes the initial interaction response.
sourcepub async fn delete_permission(
&self,
channel_id: u64,
target_id: u64
) -> Result<()>
pub async fn delete_permission(
&self,
channel_id: u64,
target_id: u64
) -> Result<()>
Deletes a permission override from a role or a member in a channel.
sourcepub async fn delete_reaction(
&self,
channel_id: u64,
message_id: u64,
user_id: Option<u64>,
reaction_type: &ReactionType
) -> Result<()>
pub async fn delete_reaction(
&self,
channel_id: u64,
message_id: u64,
user_id: Option<u64>,
reaction_type: &ReactionType
) -> Result<()>
Deletes a reaction from a message if owned by us or we have specific permissions.
sourcepub async fn delete_role(&self, guild_id: u64, role_id: u64) -> Result<()>
pub async fn delete_role(&self, guild_id: u64, role_id: u64) -> Result<()>
Deletes a role from a server. Can’t remove the default everyone role.
sourcepub async fn delete_scheduled_event(
&self,
guild_id: u64,
event_id: u64
) -> Result<()>
pub async fn delete_scheduled_event(
&self,
guild_id: u64,
event_id: u64
) -> Result<()>
Deletes a Scheduled Event from a server.
Note: Requires the Manage Events permission.
sourcepub async fn delete_sticker(
&self,
guild_id: u64,
sticker_id: u64,
audit_log_reason: Option<&str>
) -> Result<()>
pub async fn delete_sticker(
&self,
guild_id: u64,
sticker_id: u64,
audit_log_reason: Option<&str>
) -> Result<()>
Deletes a sticker from a server.
Note: Requires the Manage Emojis and Stickers permission.
sourcepub async fn delete_webhook(&self, webhook_id: u64) -> Result<()>
pub async fn delete_webhook(&self, webhook_id: u64) -> Result<()>
Deletes a Webhook
given its Id.
This method requires authentication, whereas Self::delete_webhook_with_token
does not.
Examples
Deletes a webhook given its Id:
use serenity::http::Http;
// Due to the `delete_webhook` function requiring you to authenticate, you
// must have set the token first.
let http = Http::new("token");
http.delete_webhook(245037420704169985).await?;
Ok(())
sourcepub async fn delete_webhook_with_token(
&self,
webhook_id: u64,
token: &str
) -> Result<()>
pub async fn delete_webhook_with_token(
&self,
webhook_id: u64,
token: &str
) -> Result<()>
Deletes a Webhook
given its Id and unique token.
This method does not require authentication.
Examples
Deletes a webhook given its Id and unique token:
let id = 245037420704169985;
let token = "ig5AO-wdVWpCBtUUMxmgsWryqgsW3DChbKYOINftJ4DCrUbnkedoYZD0VOH1QLr-S3sV";
http.delete_webhook_with_token(id, token).await?;
sourcepub async fn edit_channel(
&self,
channel_id: u64,
map: &JsonMap,
audit_log_reason: Option<&str>
) -> Result<GuildChannel>
pub async fn edit_channel(
&self,
channel_id: u64,
map: &JsonMap,
audit_log_reason: Option<&str>
) -> Result<GuildChannel>
Changes channel information.
sourcepub async fn edit_stage_instance(
&self,
channel_id: u64,
map: &Value
) -> Result<StageInstance>
pub async fn edit_stage_instance(
&self,
channel_id: u64,
map: &Value
) -> Result<StageInstance>
Edits a stage instance.
sourcepub async fn edit_emoji(
&self,
guild_id: u64,
emoji_id: u64,
map: &Value,
audit_log_reason: Option<&str>
) -> Result<Emoji>
pub async fn edit_emoji(
&self,
guild_id: u64,
emoji_id: u64,
map: &Value,
audit_log_reason: Option<&str>
) -> Result<Emoji>
Changes emoji information.
sourcepub async fn edit_followup_message(
&self,
interaction_token: &str,
message_id: u64,
map: &Value
) -> Result<Message>
pub async fn edit_followup_message(
&self,
interaction_token: &str,
message_id: u64,
map: &Value
) -> Result<Message>
Edits a follow-up message for an interaction.
Refer to Discord’s docs for Edit Webhook Message for field information.
sourcepub async fn edit_followup_message_and_attachments(
&self,
interaction_token: &str,
message_id: u64,
map: &Value,
new_attachments: impl IntoIterator<Item = AttachmentType<'_>>
) -> Result<Message>
pub async fn edit_followup_message_and_attachments(
&self,
interaction_token: &str,
message_id: u64,
map: &Value,
new_attachments: impl IntoIterator<Item = AttachmentType<'_>>
) -> Result<Message>
Edits a follow-up message and its attachments for an interaction.
Refer to Discord’s docs for Edit Webhook Message for field information.
sourcepub async fn get_followup_message(
&self,
interaction_token: &str,
message_id: u64
) -> Result<Message>
pub async fn get_followup_message(
&self,
interaction_token: &str,
message_id: u64
) -> Result<Message>
Get a follow-up message for an interaction.
Refer to Discord’s docs for Get Webhook Message for field information.
sourcepub async fn edit_global_application_command(
&self,
command_id: u64,
map: &Value
) -> Result<Command>
pub async fn edit_global_application_command(
&self,
command_id: u64,
map: &Value
) -> Result<Command>
Edits a global command.
Updates will be available in all guilds after 1 hour.
Refer to Discord’s docs for field information.
sourcepub async fn edit_guild(
&self,
guild_id: u64,
map: &JsonMap,
audit_log_reason: Option<&str>
) -> Result<PartialGuild>
pub async fn edit_guild(
&self,
guild_id: u64,
map: &JsonMap,
audit_log_reason: Option<&str>
) -> Result<PartialGuild>
Changes guild information.
sourcepub async fn edit_guild_application_command(
&self,
guild_id: u64,
command_id: u64,
map: &Value
) -> Result<Command>
pub async fn edit_guild_application_command(
&self,
guild_id: u64,
command_id: u64,
map: &Value
) -> Result<Command>
Edits a guild command.
Updates for guild commands will be available immediately.
Refer to Discord’s docs for field information.
sourcepub async fn edit_guild_application_command_permissions(
&self,
guild_id: u64,
command_id: u64,
map: &Value
) -> Result<CommandPermission>
pub async fn edit_guild_application_command_permissions(
&self,
guild_id: u64,
command_id: u64,
map: &Value
) -> Result<CommandPermission>
Edits a guild command permissions.
Updates for guild commands will be available immediately.
Refer to Discord’s documentation for field information.
sourcepub async fn edit_guild_application_commands_permissions(
&self,
guild_id: u64,
map: &Value
) -> Result<Vec<CommandPermission>>
pub async fn edit_guild_application_commands_permissions(
&self,
guild_id: u64,
map: &Value
) -> Result<Vec<CommandPermission>>
Edits a guild commands permissions.
Updates for guild commands will be available immediately.
Refer to Discord’s documentation for field information.
sourcepub async fn edit_guild_channel_positions(
&self,
guild_id: u64,
value: &Value
) -> Result<()>
pub async fn edit_guild_channel_positions(
&self,
guild_id: u64,
value: &Value
) -> Result<()>
Edits the positions of a guild’s channels.
sourcepub async fn edit_guild_widget(
&self,
guild_id: u64,
map: &Value
) -> Result<GuildWidget>
pub async fn edit_guild_widget(
&self,
guild_id: u64,
map: &Value
) -> Result<GuildWidget>
Edits a Guild
’s widget.
sourcepub async fn edit_guild_welcome_screen(
&self,
guild_id: u64,
map: &Value
) -> Result<GuildWelcomeScreen>
pub async fn edit_guild_welcome_screen(
&self,
guild_id: u64,
map: &Value
) -> Result<GuildWelcomeScreen>
Edits a guild welcome screen.
sourcepub async fn edit_member(
&self,
guild_id: u64,
user_id: u64,
map: &JsonMap,
audit_log_reason: Option<&str>
) -> Result<Member>
pub async fn edit_member(
&self,
guild_id: u64,
user_id: u64,
map: &JsonMap,
audit_log_reason: Option<&str>
) -> Result<Member>
Does specific actions to a member.
sourcepub async fn edit_message(
&self,
channel_id: u64,
message_id: u64,
map: &Value
) -> Result<Message>
pub async fn edit_message(
&self,
channel_id: u64,
message_id: u64,
map: &Value
) -> Result<Message>
Edits a message by Id.
Note: Only the author of a message can modify it.
sourcepub async fn edit_message_and_attachments(
&self,
channel_id: u64,
message_id: u64,
map: &Value,
new_attachments: impl IntoIterator<Item = AttachmentType<'_>>
) -> Result<Message>
pub async fn edit_message_and_attachments(
&self,
channel_id: u64,
message_id: u64,
map: &Value,
new_attachments: impl IntoIterator<Item = AttachmentType<'_>>
) -> Result<Message>
Edits a message and its attachments by Id.
Note: Only the author of a message can modify it.
sourcepub async fn crosspost_message(
&self,
channel_id: u64,
message_id: u64
) -> Result<Message>
pub async fn crosspost_message(
&self,
channel_id: u64,
message_id: u64
) -> Result<Message>
Crossposts a message by Id.
Note: Only available on news channels.
sourcepub async fn edit_member_me(&self, guild_id: u64, map: &JsonMap) -> Result<Member>
pub async fn edit_member_me(&self, guild_id: u64, map: &JsonMap) -> Result<Member>
Edits the current member for the provided Guild
via its Id.
sourcepub async fn follow_news_channel(
&self,
news_channel_id: u64,
target_channel_id: u64
) -> Result<FollowedChannel>
pub async fn follow_news_channel(
&self,
news_channel_id: u64,
target_channel_id: u64
) -> Result<FollowedChannel>
Follow a News Channel to send messages to a target channel.
sourcepub async fn get_original_interaction_response(
&self,
interaction_token: &str
) -> Result<Message>
pub async fn get_original_interaction_response(
&self,
interaction_token: &str
) -> Result<Message>
Gets the initial interaction response.
sourcepub async fn edit_original_interaction_response(
&self,
interaction_token: &str,
map: &Value
) -> Result<Message>
pub async fn edit_original_interaction_response(
&self,
interaction_token: &str,
map: &Value
) -> Result<Message>
Edits the initial interaction response.
Refer to Discord’s docs for Edit Webhook Message for field information.
sourcepub async fn edit_profile(&self, map: &JsonMap) -> Result<CurrentUser>
pub async fn edit_profile(&self, map: &JsonMap) -> Result<CurrentUser>
Edits the current user’s profile settings.
sourcepub async fn edit_role(
&self,
guild_id: u64,
role_id: u64,
map: &JsonMap,
audit_log_reason: Option<&str>
) -> Result<Role>
pub async fn edit_role(
&self,
guild_id: u64,
role_id: u64,
map: &JsonMap,
audit_log_reason: Option<&str>
) -> Result<Role>
Changes a role in a guild.
sourcepub async fn edit_role_position(
&self,
guild_id: u64,
role_id: u64,
position: u64,
audit_log_reason: Option<&str>
) -> Result<Vec<Role>>
pub async fn edit_role_position(
&self,
guild_id: u64,
role_id: u64,
position: u64,
audit_log_reason: Option<&str>
) -> Result<Vec<Role>>
Changes the position of a role in a guild.
sourcepub async fn edit_scheduled_event(
&self,
guild_id: u64,
event_id: u64,
map: &JsonMap,
audit_log_reason: Option<&str>
) -> Result<ScheduledEvent>
pub async fn edit_scheduled_event(
&self,
guild_id: u64,
event_id: u64,
map: &JsonMap,
audit_log_reason: Option<&str>
) -> Result<ScheduledEvent>
Modifies a scheduled event.
Note: Requires the Manage Events permission.
sourcepub async fn edit_sticker(
&self,
guild_id: u64,
sticker_id: u64,
map: &JsonMap,
audit_log_reason: Option<&str>
) -> Result<Sticker>
pub async fn edit_sticker(
&self,
guild_id: u64,
sticker_id: u64,
map: &JsonMap,
audit_log_reason: Option<&str>
) -> Result<Sticker>
Changes a sticker in a guild.
Note: Requires the Manage Emojis and Stickers permission.
sourcepub async fn edit_thread(
&self,
channel_id: u64,
map: &JsonMap
) -> Result<GuildChannel>
pub async fn edit_thread(
&self,
channel_id: u64,
map: &JsonMap
) -> Result<GuildChannel>
Edits a thread channel in the GuildChannel
given its Id.
sourcepub async fn edit_voice_state(
&self,
guild_id: u64,
user_id: u64,
map: &JsonMap
) -> Result<()>
pub async fn edit_voice_state(
&self,
guild_id: u64,
user_id: u64,
map: &JsonMap
) -> Result<()>
Changes another user’s voice state in a stage channel.
The Value is a map with values of:
- channel_id: ID of the channel the user is currently in (required)
- suppress: Bool which toggles user’s suppressed state. Setting this
to
false
will invite the user to speak.
Example
Suppress a user
use serenity::http::Http;
use serenity::json::{json, prelude::*};
let guild_id = 187450744427773963;
let user_id = 150443906511667200;
let value = json!({
"channel_id": "826929611849334784",
"suppress": true,
});
let map = value.as_object().unwrap();
// Edit state for another user
http.edit_voice_state(guild_id, user_id, &map).await?;
sourcepub async fn edit_voice_state_me(
&self,
guild_id: u64,
map: &JsonMap
) -> Result<()>
pub async fn edit_voice_state_me(
&self,
guild_id: u64,
map: &JsonMap
) -> Result<()>
Changes the current user’s voice state in a stage channel.
The Value is a map with values of:
- channel_id: ID of the channel the user is currently in (required)
- suppress: Bool which toggles user’s suppressed state. Setting this
to
false
will invite the user to speak. - request_to_speak_timestamp: ISO8601 timestamp to set the user’s request to speak. This can be any present or future time.
Example
Unsuppress the current bot user
use serenity::http::Http;
use serenity::json::{json, prelude::*};
let guild_id = 187450744427773963;
let value = json!({
"channel_id": "826929611849334784",
"suppress": false,
"request_to_speak_timestamp": "2021-03-31T18:45:31.297561+00:00"
});
let map = value.as_object().unwrap();
// Edit state for current user
http.edit_voice_state_me(guild_id, &map).await?;
sourcepub async fn edit_webhook(
&self,
webhook_id: u64,
map: &Value,
audit_log_reason: Option<&str>
) -> Result<Webhook>
pub async fn edit_webhook(
&self,
webhook_id: u64,
map: &Value,
audit_log_reason: Option<&str>
) -> Result<Webhook>
Edits a the webhook with the given data.
The Value is a map with optional values of:
- avatar: base64-encoded 128x128 image for the webhook’s default avatar (optional);
- name: the name of the webhook, limited to between 2 and 100 characters long.
Note that, unlike with Self::create_webhook
, all values are optional.
This method requires authentication, whereas Self::edit_webhook_with_token
does not.
Examples
Edit the image of a webhook given its Id and unique token:
use serenity::http::Http;
use serenity::json::json;
let id = 245037420704169985;
let image = serenity::utils::read_image("./webhook_img.png")?;
let map = json!({
"avatar": image,
});
let edited = http.edit_webhook(id, &map, None).await?;
sourcepub async fn edit_webhook_with_token(
&self,
webhook_id: u64,
token: &str,
map: &JsonMap
) -> Result<Webhook>
pub async fn edit_webhook_with_token(
&self,
webhook_id: u64,
token: &str,
map: &JsonMap
) -> Result<Webhook>
Edits the webhook with the given data.
Refer to the documentation for Self::edit_webhook
for more information.
This method does not require authentication.
Examples
Edit the name of a webhook given its Id and unique token:
use serenity::http::Http;
use serenity::json::prelude::*;
let id = 245037420704169985;
let token = "ig5AO-wdVWpCBtUUMxmgsWryqgsW3DChbKYOINftJ4DCrUbnkedoYZD0VOH1QLr-S3sV";
let value = json!({"name": "new name"});
let map = value.as_object().unwrap();
let edited = http.edit_webhook_with_token(id, token, map).await?;
sourcepub async fn execute_webhook(
&self,
webhook_id: u64,
token: &str,
wait: bool,
map: &JsonMap
) -> Result<Option<Message>>
pub async fn execute_webhook(
&self,
webhook_id: u64,
token: &str,
wait: bool,
map: &JsonMap
) -> Result<Option<Message>>
Executes a webhook, posting a Message
in the webhook’s associated
Channel
.
This method does not require authentication.
Pass true
to wait
to wait for server confirmation of the message sending
before receiving a response. From the Discord docs:
waits for server confirmation of message send before response, and returns the created message body (defaults to false; when false a message that is not saved does not return an error)
The map can optionally contain the following data:
avatar_url
: Override the default avatar of the webhook with a URL.tts
: Whether this is a text-to-speech message (defaults tofalse
).username
: Override the default username of the webhook.
Additionally, at least one of the following must be given:
content
: The content of the message.embeds
: An array of rich embeds.
Note: For embed objects, all fields are registered by Discord except for
height
, provider
, proxy_url
, type
(it will always be rich
),
video
, and width
. The rest will be determined by Discord.
Examples
Sending a webhook with message content of test
:
use serenity::http::Http;
use serenity::json::prelude::*;
let id = 245037420704169985;
let token = "ig5AO-wdVWpCBtUUMxmgsWryqgsW3DChbKYOINftJ4DCrUbnkedoYZD0VOH1QLr-S3sV";
let value = json!({"content": "test"});
let map = value.as_object().unwrap();
let message = http.execute_webhook(id, token, true, map).await?;
sourcepub async fn execute_webhook_with_files<'a, T, It: IntoIterator<Item = T>>(
&self,
webhook_id: u64,
token: &str,
wait: bool,
files: It,
map: &JsonMap
) -> Result<Option<Message>> where
T: Into<AttachmentType<'a>>,
pub async fn execute_webhook_with_files<'a, T, It: IntoIterator<Item = T>>(
&self,
webhook_id: u64,
token: &str,
wait: bool,
files: It,
map: &JsonMap
) -> Result<Option<Message>> where
T: Into<AttachmentType<'a>>,
Send file(s) over a webhook.
Errors
Returns an
HttpError::UnsuccessfulRequest(ErrorResponse)
if the files are too large to send.
pub async fn get_webhook_message(
&self,
webhook_id: u64,
token: &str,
message_id: u64
) -> Result<Message>
sourcepub async fn edit_webhook_message(
&self,
webhook_id: u64,
token: &str,
message_id: u64,
map: &JsonMap
) -> Result<Message>
pub async fn edit_webhook_message(
&self,
webhook_id: u64,
token: &str,
message_id: u64,
map: &JsonMap
) -> Result<Message>
Edits a webhook’s message by Id.
sourcepub async fn delete_webhook_message(
&self,
webhook_id: u64,
token: &str,
message_id: u64
) -> Result<()>
pub async fn delete_webhook_message(
&self,
webhook_id: u64,
token: &str,
message_id: u64
) -> Result<()>
Deletes a webhook’s message by Id.
sourcepub async fn get_active_maintenances(&self) -> Result<Vec<Maintenance>>
pub async fn get_active_maintenances(&self) -> Result<Vec<Maintenance>>
Gets the active maintenances from Discord’s Status API.
Does not require authentication.
sourcepub async fn get_bans(&self, guild_id: u64) -> Result<Vec<Ban>>
pub async fn get_bans(&self, guild_id: u64) -> Result<Vec<Ban>>
Gets all the users that are banned in specific guild.
sourcepub async fn get_audit_logs(
&self,
guild_id: u64,
action_type: Option<u8>,
user_id: Option<u64>,
before: Option<u64>,
limit: Option<u8>
) -> Result<AuditLogs>
pub async fn get_audit_logs(
&self,
guild_id: u64,
action_type: Option<u8>,
user_id: Option<u64>,
before: Option<u64>,
limit: Option<u8>
) -> Result<AuditLogs>
Gets all audit logs in a specific guild.
sourcepub async fn get_automod_rules(&self, guild_id: u64) -> Result<Vec<Rule>>
pub async fn get_automod_rules(&self, guild_id: u64) -> Result<Vec<Rule>>
Retrieves all auto moderation rules in a guild.
This method requires MANAGE_GUILD
permissions.
sourcepub async fn get_automod_rule(&self, guild_id: u64, rule_id: u64) -> Result<Rule>
pub async fn get_automod_rule(&self, guild_id: u64, rule_id: u64) -> Result<Rule>
Retrieves an auto moderation rule in a guild.
This method requires MANAGE_GUILD
permissions.
sourcepub async fn create_automod_rule(
&self,
guild_id: u64,
map: &JsonMap
) -> Result<Rule>
pub async fn create_automod_rule(
&self,
guild_id: u64,
map: &JsonMap
) -> Result<Rule>
Creates an auto moderation rule in a guild.
This method requires MANAGE_GUILD
permissions.
sourcepub async fn edit_automod_rule(
&self,
guild_id: u64,
rule_id: u64,
map: &JsonMap
) -> Result<Rule>
pub async fn edit_automod_rule(
&self,
guild_id: u64,
rule_id: u64,
map: &JsonMap
) -> Result<Rule>
Retrieves an auto moderation rule in a guild.
This method requires MANAGE_GUILD
permissions.
sourcepub async fn delete_automod_rule(&self, guild_id: u64, rule_id: u64) -> Result<()>
pub async fn delete_automod_rule(&self, guild_id: u64, rule_id: u64) -> Result<()>
Deletes an auto moderation rule in a guild.
This method requires MANAGE_GUILD
permissions.
sourcepub async fn get_bot_gateway(&self) -> Result<BotGateway>
pub async fn get_bot_gateway(&self) -> Result<BotGateway>
Gets current bot gateway.
sourcepub async fn get_channel_invites(
&self,
channel_id: u64
) -> Result<Vec<RichInvite>>
pub async fn get_channel_invites(
&self,
channel_id: u64
) -> Result<Vec<RichInvite>>
Gets all invites for a channel.
sourcepub async fn get_channel_thread_members(
&self,
channel_id: u64
) -> Result<Vec<ThreadMember>>
pub async fn get_channel_thread_members(
&self,
channel_id: u64
) -> Result<Vec<ThreadMember>>
Gets all thread members for a thread.
sourcepub async fn get_guild_active_threads(
&self,
guild_id: u64
) -> Result<ThreadsData>
pub async fn get_guild_active_threads(
&self,
guild_id: u64
) -> Result<ThreadsData>
Gets all active threads from a guild.
sourcepub async fn get_channel_archived_public_threads(
&self,
channel_id: u64,
before: Option<u64>,
limit: Option<u64>
) -> Result<ThreadsData>
pub async fn get_channel_archived_public_threads(
&self,
channel_id: u64,
before: Option<u64>,
limit: Option<u64>
) -> Result<ThreadsData>
Gets all archived public threads from a channel.
sourcepub async fn get_channel_archived_private_threads(
&self,
channel_id: u64,
before: Option<u64>,
limit: Option<u64>
) -> Result<ThreadsData>
pub async fn get_channel_archived_private_threads(
&self,
channel_id: u64,
before: Option<u64>,
limit: Option<u64>
) -> Result<ThreadsData>
Gets all archived private threads from a channel.
sourcepub async fn get_channel_joined_archived_private_threads(
&self,
channel_id: u64,
before: Option<u64>,
limit: Option<u64>
) -> Result<ThreadsData>
pub async fn get_channel_joined_archived_private_threads(
&self,
channel_id: u64,
before: Option<u64>,
limit: Option<u64>
) -> Result<ThreadsData>
Gets all archived private threads joined from a channel.
sourcepub async fn join_thread_channel(&self, channel_id: u64) -> Result<()>
pub async fn join_thread_channel(&self, channel_id: u64) -> Result<()>
Joins a thread channel.
sourcepub async fn leave_thread_channel(&self, channel_id: u64) -> Result<()>
pub async fn leave_thread_channel(&self, channel_id: u64) -> Result<()>
Leaves a thread channel.
sourcepub async fn add_thread_channel_member(
&self,
channel_id: u64,
user_id: u64
) -> Result<()>
pub async fn add_thread_channel_member(
&self,
channel_id: u64,
user_id: u64
) -> Result<()>
Adds a member to a thread channel.
sourcepub async fn remove_thread_channel_member(
&self,
channel_id: u64,
user_id: u64
) -> Result<()>
pub async fn remove_thread_channel_member(
&self,
channel_id: u64,
user_id: u64
) -> Result<()>
Removes a member from a thread channel.
sourcepub async fn get_channel(&self, channel_id: u64) -> Result<Channel>
pub async fn get_channel(&self, channel_id: u64) -> Result<Channel>
Gets channel information.
sourcepub async fn get_channels(&self, guild_id: u64) -> Result<Vec<GuildChannel>>
pub async fn get_channels(&self, guild_id: u64) -> Result<Vec<GuildChannel>>
Gets all channels in a guild.
sourcepub async fn get_stage_instance(&self, channel_id: u64) -> Result<StageInstance>
pub async fn get_stage_instance(&self, channel_id: u64) -> Result<StageInstance>
Gets a stage instance.
sourcepub async fn get_current_application_info(
&self
) -> Result<CurrentApplicationInfo>
pub async fn get_current_application_info(
&self
) -> Result<CurrentApplicationInfo>
Gets information about the current application.
Note: Only applications may use this endpoint.
sourcepub async fn get_current_user(&self) -> Result<CurrentUser>
pub async fn get_current_user(&self) -> Result<CurrentUser>
Gets information about the user we’re connected with.
sourcepub async fn get_emojis(&self, guild_id: u64) -> Result<Vec<Emoji>>
pub async fn get_emojis(&self, guild_id: u64) -> Result<Vec<Emoji>>
Gets all emojis of a guild.
sourcepub async fn get_emoji(&self, guild_id: u64, emoji_id: u64) -> Result<Emoji>
pub async fn get_emoji(&self, guild_id: u64, emoji_id: u64) -> Result<Emoji>
Gets information about an emoji in a guild.
sourcepub async fn get_gateway(&self) -> Result<Gateway>
pub async fn get_gateway(&self) -> Result<Gateway>
Gets current gateway.
sourcepub async fn get_global_application_commands(&self) -> Result<Vec<Command>>
pub async fn get_global_application_commands(&self) -> Result<Vec<Command>>
Fetches all of the global commands for your application.
sourcepub async fn get_global_application_command(
&self,
command_id: u64
) -> Result<Command>
pub async fn get_global_application_command(
&self,
command_id: u64
) -> Result<Command>
Fetches a global commands for your application by its Id.
sourcepub async fn get_guild(&self, guild_id: u64) -> Result<PartialGuild>
pub async fn get_guild(&self, guild_id: u64) -> Result<PartialGuild>
Gets guild information.
sourcepub async fn get_guild_with_counts(&self, guild_id: u64) -> Result<PartialGuild>
pub async fn get_guild_with_counts(&self, guild_id: u64) -> Result<PartialGuild>
Gets guild information with counts.
sourcepub async fn get_guild_application_commands(
&self,
guild_id: u64
) -> Result<Vec<Command>>
pub async fn get_guild_application_commands(
&self,
guild_id: u64
) -> Result<Vec<Command>>
Fetches all of the guild commands for your application for a specific guild.
sourcepub async fn get_guild_application_command(
&self,
guild_id: u64,
command_id: u64
) -> Result<Command>
pub async fn get_guild_application_command(
&self,
guild_id: u64,
command_id: u64
) -> Result<Command>
Fetches a guild command by its Id.
sourcepub async fn get_guild_application_commands_permissions(
&self,
guild_id: u64
) -> Result<Vec<CommandPermission>>
pub async fn get_guild_application_commands_permissions(
&self,
guild_id: u64
) -> Result<Vec<CommandPermission>>
Fetches all of the guild commands permissions for your application for a specific guild.
sourcepub async fn get_guild_application_command_permissions(
&self,
guild_id: u64,
command_id: u64
) -> Result<CommandPermission>
pub async fn get_guild_application_command_permissions(
&self,
guild_id: u64,
command_id: u64
) -> Result<CommandPermission>
Gives the guild command permission for your application for a specific guild.
sourcepub async fn get_guild_widget(&self, guild_id: u64) -> Result<GuildWidget>
pub async fn get_guild_widget(&self, guild_id: u64) -> Result<GuildWidget>
Gets a guild widget information.
sourcepub async fn get_guild_preview(&self, guild_id: u64) -> Result<GuildPreview>
pub async fn get_guild_preview(&self, guild_id: u64) -> Result<GuildPreview>
Gets a guild preview.
sourcepub async fn get_guild_welcome_screen(
&self,
guild_id: u64
) -> Result<GuildWelcomeScreen>
pub async fn get_guild_welcome_screen(
&self,
guild_id: u64
) -> Result<GuildWelcomeScreen>
Gets a guild welcome screen information.
sourcepub async fn get_guild_integrations(
&self,
guild_id: u64
) -> Result<Vec<Integration>>
pub async fn get_guild_integrations(
&self,
guild_id: u64
) -> Result<Vec<Integration>>
Gets integrations that a guild has.
sourcepub async fn get_guild_invites(&self, guild_id: u64) -> Result<Vec<RichInvite>>
pub async fn get_guild_invites(&self, guild_id: u64) -> Result<Vec<RichInvite>>
Gets all invites to a guild.
sourcepub async fn get_guild_vanity_url(&self, guild_id: u64) -> Result<String>
pub async fn get_guild_vanity_url(&self, guild_id: u64) -> Result<String>
Gets a guild’s vanity URL if it has one.
sourcepub async fn get_guild_members(
&self,
guild_id: u64,
limit: Option<u64>,
after: Option<u64>
) -> Result<Vec<Member>>
pub async fn get_guild_members(
&self,
guild_id: u64,
limit: Option<u64>,
after: Option<u64>
) -> Result<Vec<Member>>
Gets the members of a guild. Optionally pass a limit
and the Id of the
user to offset the result by.
sourcepub async fn get_guild_prune_count(
&self,
guild_id: u64,
map: &Value
) -> Result<GuildPrune>
pub async fn get_guild_prune_count(
&self,
guild_id: u64,
map: &Value
) -> Result<GuildPrune>
Gets the amount of users that can be pruned.
sourcepub async fn get_guild_regions(&self, guild_id: u64) -> Result<Vec<VoiceRegion>>
pub async fn get_guild_regions(&self, guild_id: u64) -> Result<Vec<VoiceRegion>>
Gets regions that a guild can use. If a guild has the VIP_REGIONS
feature
enabled, then additional VIP-only regions are returned.
sourcepub async fn get_guild_roles(&self, guild_id: u64) -> Result<Vec<Role>>
pub async fn get_guild_roles(&self, guild_id: u64) -> Result<Vec<Role>>
Retrieves a list of roles in a Guild
.
sourcepub async fn get_scheduled_event(
&self,
guild_id: u64,
event_id: u64,
with_user_count: bool
) -> Result<ScheduledEvent>
pub async fn get_scheduled_event(
&self,
guild_id: u64,
event_id: u64,
with_user_count: bool
) -> Result<ScheduledEvent>
Gets a scheduled event by Id.
Note: Requires the Manage Events permission.
sourcepub async fn get_scheduled_events(
&self,
guild_id: u64,
with_user_count: bool
) -> Result<Vec<ScheduledEvent>>
pub async fn get_scheduled_events(
&self,
guild_id: u64,
with_user_count: bool
) -> Result<Vec<ScheduledEvent>>
Gets a list of all scheduled events for the corresponding guild.
Note: Requires the Manage Events permission.
sourcepub async fn get_scheduled_event_users(
&self,
guild_id: u64,
event_id: u64,
limit: Option<u64>,
target: Option<UserPagination>,
with_member: Option<bool>
) -> Result<Vec<ScheduledEventUser>>
pub async fn get_scheduled_event_users(
&self,
guild_id: u64,
event_id: u64,
limit: Option<u64>,
target: Option<UserPagination>,
with_member: Option<bool>
) -> Result<Vec<ScheduledEventUser>>
Gets a list of all interested users for the corresponding scheduled event, with additional options for filtering.
If limit
is left unset, by default at most 100 users are returned.
If target
is set, then users will be filtered by Id, such that their Id comes before or
after the provided UserId
wrapped by the UserPagination
.
If with_member
is set to Some(true)
, then the member
field of the user struct will
be populated with Guild Member
information, if the interested user is a member of the
guild the event takes place in.
sourcepub async fn get_guild_stickers(&self, guild_id: u64) -> Result<Vec<Sticker>>
pub async fn get_guild_stickers(&self, guild_id: u64) -> Result<Vec<Sticker>>
Retrieves a list of stickers in a Guild
.
sourcepub async fn get_guild_sticker(
&self,
guild_id: u64,
sticker_id: u64
) -> Result<Sticker>
pub async fn get_guild_sticker(
&self,
guild_id: u64,
sticker_id: u64
) -> Result<Sticker>
Retrieves a single sticker in a Guild
.
sourcepub async fn get_guilds(
&self,
target: Option<&GuildPagination>,
limit: Option<u64>
) -> Result<Vec<GuildInfo>>
pub async fn get_guilds(
&self,
target: Option<&GuildPagination>,
limit: Option<u64>
) -> Result<Vec<GuildInfo>>
Gets a paginated list of the current user’s guilds.
The limit
has a maximum value of 100.
Examples
Get the first 10 guilds after a certain guild’s Id:
use serenity::http::GuildPagination;
use serenity::model::id::GuildId;
let guild_id = GuildId(81384788765712384);
let guilds = http.get_guilds(Some(&GuildPagination::After(guild_id)), Some(10)).await?;
sourcepub async fn get_invite(
&self,
code: &str,
member_counts: bool,
expiration: bool,
event_id: Option<u64>
) -> Result<Invite>
pub async fn get_invite(
&self,
code: &str,
member_counts: bool,
expiration: bool,
event_id: Option<u64>
) -> Result<Invite>
Gets information about a specific invite.
Arguments
code
- The invite code.member_counts
- Whether to include information about the current number of members in the server that the invite belongs to.expiration
- Whether to include information about when the invite expires.event_id
- An optional server event ID to include with the invite.
More information about these arguments can be found on Discord’s API documentation.
sourcepub async fn get_member(&self, guild_id: u64, user_id: u64) -> Result<Member>
pub async fn get_member(&self, guild_id: u64, user_id: u64) -> Result<Member>
Gets member of a guild.
sourcepub async fn get_message(
&self,
channel_id: u64,
message_id: u64
) -> Result<Message>
pub async fn get_message(
&self,
channel_id: u64,
message_id: u64
) -> Result<Message>
Gets a message by an Id, bots only.
sourcepub async fn get_messages(
&self,
channel_id: u64,
query: &str
) -> Result<Vec<Message>>
pub async fn get_messages(
&self,
channel_id: u64,
query: &str
) -> Result<Vec<Message>>
Gets X messages from a channel.
sourcepub async fn get_nitro_stickers(&self) -> Result<Vec<StickerPack>>
pub async fn get_nitro_stickers(&self) -> Result<Vec<StickerPack>>
Retrieves a list of all nitro sticker packs.
sourcepub async fn get_pins(&self, channel_id: u64) -> Result<Vec<Message>>
pub async fn get_pins(&self, channel_id: u64) -> Result<Vec<Message>>
Gets all pins of a channel.
sourcepub async fn get_reaction_users(
&self,
channel_id: u64,
message_id: u64,
reaction_type: &ReactionType,
limit: u8,
after: Option<u64>
) -> Result<Vec<User>>
pub async fn get_reaction_users(
&self,
channel_id: u64,
message_id: u64,
reaction_type: &ReactionType,
limit: u8,
after: Option<u64>
) -> Result<Vec<User>>
Gets user Ids based on their reaction to a message. This endpoint is dumb.
sourcepub async fn get_sticker(&self, sticker_id: u64) -> Result<Sticker>
pub async fn get_sticker(&self, sticker_id: u64) -> Result<Sticker>
Gets a sticker.
sourcepub async fn get_unresolved_incidents(&self) -> Result<Vec<Incident>>
pub async fn get_unresolved_incidents(&self) -> Result<Vec<Incident>>
Gets the current unresolved incidents from Discord’s Status API.
Does not require authentication.
sourcepub async fn get_upcoming_maintenances(&self) -> Result<Vec<Maintenance>>
pub async fn get_upcoming_maintenances(&self) -> Result<Vec<Maintenance>>
Gets the upcoming (planned) maintenances from Discord’s Status API.
Does not require authentication.
sourcepub async fn get_user_connections(&self) -> Result<Vec<Connection>>
pub async fn get_user_connections(&self) -> Result<Vec<Connection>>
Gets the current user’s third party connections.
This method only works for user tokens with the
Connections
OAuth2 scope.
sourcepub async fn get_user_dm_channels(&self) -> Result<Vec<PrivateChannel>>
pub async fn get_user_dm_channels(&self) -> Result<Vec<PrivateChannel>>
Gets our DM channels.
sourcepub async fn get_voice_regions(&self) -> Result<Vec<VoiceRegion>>
pub async fn get_voice_regions(&self) -> Result<Vec<VoiceRegion>>
Gets all voice regions.
sourcepub async fn get_webhook(&self, webhook_id: u64) -> Result<Webhook>
pub async fn get_webhook(&self, webhook_id: u64) -> Result<Webhook>
Retrieves a webhook given its Id.
This method requires authentication, whereas Http::get_webhook_with_token
and
Http::get_webhook_from_url
do not.
Examples
Retrieve a webhook by Id:
let id = 245037420704169985;
let webhook = http.get_webhook(id).await?;
sourcepub async fn get_webhook_with_token(
&self,
webhook_id: u64,
token: &str
) -> Result<Webhook>
pub async fn get_webhook_with_token(
&self,
webhook_id: u64,
token: &str
) -> Result<Webhook>
Retrieves a webhook given its Id and unique token.
This method does not require authentication.
Examples
Retrieve a webhook by Id and its unique token:
let id = 245037420704169985;
let token = "ig5AO-wdVWpCBtUUMxmgsWryqgsW3DChbKYOINftJ4DCrUbnkedoYZD0VOH1QLr-S3sV";
let webhook = http.get_webhook_with_token(id, token).await?;
sourcepub async fn get_webhook_from_url(&self, url: &str) -> Result<Webhook>
pub async fn get_webhook_from_url(&self, url: &str) -> Result<Webhook>
Retrieves a webhook given its url.
This method does not require authentication
Examples
Retrieve a webhook by url:
let url = "https://discord.com/api/webhooks/245037420704169985/ig5AO-wdVWpCBtUUMxmgsWryqgsW3DChbKYOINftJ4DCrUbnkedoYZD0VOH1QLr-S3sV";
let webhook = http.get_webhook_from_url(url).await?;
sourcepub async fn kick_member(&self, guild_id: u64, user_id: u64) -> Result<()>
pub async fn kick_member(&self, guild_id: u64, user_id: u64) -> Result<()>
Kicks a member from a guild.
sourcepub async fn kick_member_with_reason(
&self,
guild_id: u64,
user_id: u64,
reason: &str
) -> Result<()>
pub async fn kick_member_with_reason(
&self,
guild_id: u64,
user_id: u64,
reason: &str
) -> Result<()>
Kicks a member from a guild with a provided reason.
sourcepub async fn leave_guild(&self, guild_id: u64) -> Result<()>
pub async fn leave_guild(&self, guild_id: u64) -> Result<()>
Leaves a guild.
sourcepub async fn send_files<'a, T, It: IntoIterator<Item = T>>(
&self,
channel_id: u64,
files: It,
map: &JsonMap
) -> Result<Message> where
T: Into<AttachmentType<'a>>,
pub async fn send_files<'a, T, It: IntoIterator<Item = T>>(
&self,
channel_id: u64,
files: It,
map: &JsonMap
) -> Result<Message> where
T: Into<AttachmentType<'a>>,
Sends file(s) to a channel.
Errors
Returns an
HttpError::UnsuccessfulRequest(ErrorResponse)
if the files are too large to send.
sourcepub async fn send_message(&self, channel_id: u64, map: &Value) -> Result<Message>
pub async fn send_message(&self, channel_id: u64, map: &Value) -> Result<Message>
Sends a message to a channel.
sourcepub async fn pin_message(
&self,
channel_id: u64,
message_id: u64,
audit_log_reason: Option<&str>
) -> Result<()>
pub async fn pin_message(
&self,
channel_id: u64,
message_id: u64,
audit_log_reason: Option<&str>
) -> Result<()>
Pins a message in a channel.
sourcepub async fn remove_ban(
&self,
guild_id: u64,
user_id: u64,
audit_log_reason: Option<&str>
) -> Result<()>
pub async fn remove_ban(
&self,
guild_id: u64,
user_id: u64,
audit_log_reason: Option<&str>
) -> Result<()>
Unbans a user from a guild.
sourcepub async fn remove_member_role(
&self,
guild_id: u64,
user_id: u64,
role_id: u64,
audit_log_reason: Option<&str>
) -> Result<()>
pub async fn remove_member_role(
&self,
guild_id: u64,
user_id: u64,
role_id: u64,
audit_log_reason: Option<&str>
) -> Result<()>
Deletes a single Role
from a Member
in a Guild
.
Note: Requires the Manage Roles permission and respect of role hierarchy.
sourcepub async fn search_guild_members(
&self,
guild_id: u64,
query: &str,
limit: Option<u64>
) -> Result<Vec<Member>>
pub async fn search_guild_members(
&self,
guild_id: u64,
query: &str,
limit: Option<u64>
) -> Result<Vec<Member>>
sourcepub async fn start_guild_prune(
&self,
guild_id: u64,
days: u64,
audit_log_reason: Option<&str>
) -> Result<GuildPrune>
pub async fn start_guild_prune(
&self,
guild_id: u64,
days: u64,
audit_log_reason: Option<&str>
) -> Result<GuildPrune>
Starts removing some members from a guild based on the last time they’ve been online.
sourcepub async fn start_integration_sync(
&self,
guild_id: u64,
integration_id: u64
) -> Result<()>
pub async fn start_integration_sync(
&self,
guild_id: u64,
integration_id: u64
) -> Result<()>
Starts syncing an integration with a guild.
sourcepub fn start_typing(self: &Arc<Self>, channel_id: u64) -> Result<Typing>
pub fn start_typing(self: &Arc<Self>, channel_id: u64) -> Result<Typing>
Starts typing in the specified Channel
for an indefinite period of time.
Returns Typing
that is used to trigger the typing. Typing::stop
must be called
on the returned struct to stop typing. Note that on some clients, typing may persist
for a few seconds after Typing::stop
is called.
Typing is also stopped when the struct is dropped.
If a message is sent while typing is triggered, the user will stop typing for a brief period
of time and then resume again until either Typing::stop
is called or the struct is dropped.
This should rarely be used for bots, although it is a good indicator that a long-running command is still being processed.
Examples
// Initiate typing (assuming http is `Arc<Http>`)
let typing = http.start_typing(7)?;
// Run some long-running process
long_process();
// Stop typing
typing.stop();
sourcepub async fn unpin_message(
&self,
channel_id: u64,
message_id: u64,
audit_log_reason: Option<&str>
) -> Result<()>
pub async fn unpin_message(
&self,
channel_id: u64,
message_id: u64,
audit_log_reason: Option<&str>
) -> Result<()>
Unpins a message from a channel.
sourcepub async fn fire<T: DeserializeOwned>(&self, req: Request<'_>) -> Result<T>
pub async fn fire<T: DeserializeOwned>(&self, req: Request<'_>) -> Result<T>
Fires off a request, deserializing the response reader via the given type bound.
If you don’t need to deserialize the response and want the response instance
itself, use Self::request
.
Examples
Create a new message via the RouteInfo::CreateMessage
endpoint and
deserialize the response into a Message
:
use serenity::{
http::{
routing::RouteInfo,
request::RequestBuilder,
},
model::channel::Message,
};
let bytes = vec![
// payload bytes here
];
let channel_id = 381880193700069377;
let route_info = RouteInfo::CreateMessage { channel_id };
let mut request = RequestBuilder::new(route_info);
request.body(Some(&bytes));
let message = http.fire::<Message>(request.build()).await?;
println!("Message content: {}", message.content);
Errors
If there is an error, it will be either Error::Http
or Error::Json
.
sourcepub async fn request(&self, req: Request<'_>) -> Result<ReqwestResponse>
pub async fn request(&self, req: Request<'_>) -> Result<ReqwestResponse>
Performs a request, ratelimiting it if necessary.
Returns the raw reqwest Response. Use Self::fire
to deserialize the response
into some type.
Examples
Send a body of bytes over the RouteInfo::CreateMessage
endpoint:
use serenity::http::{
request::RequestBuilder,
routing::RouteInfo,
};
let bytes = vec![
// payload bytes here
];
let channel_id = 381880193700069377;
let route_info = RouteInfo::CreateMessage { channel_id };
let mut request = RequestBuilder::new(route_info);
request.body(Some(&bytes));
let response = http.request(request.build()).await?;
println!("Response successful?: {}", response.status().is_success());
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Http
impl Send for Http
impl Sync for Http
impl Unpin for Http
impl !UnwindSafe for Http
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more