Skip to main content

Http

Struct Http 

Source
pub struct Http {
    pub client: Client,
    pub base_url: String,
    /* private fields */
}
Expand description

HTTP client for making REST API calls.

Created automatically by the client builder. Available as ctx.http in event handlers or directly if you just need REST calls without a gateway connection:

use fluxer::http::Http;

#[tokio::main]
async fn main() {
    let http = Http::new("your-bot-token", "https://api.fluxer.app/v1".to_string());
    let me = http.get_me().await.unwrap();
    println!("Bot user: {}", me.username);
}

Fields§

§client: Client§base_url: String

Implementations§

Source§

impl Http

Source

pub fn new(token: &str, base_url: String) -> Self

Creates a new HTTP client. The token is sent as Bot {token} in the Authorization header on every request.

Source

pub fn get_token(&self) -> &str

Source

pub async fn get_gateway(&self) -> Result<String, ClientError>

Fetches the gateway URL. Used internally during connection setup.

Source

pub async fn get_me(&self) -> Result<User, ClientError>

Fetches the bot’s own user object.

Source

pub async fn get_user(&self, user_id: &str) -> Result<User, ClientError>

Fetches a user by ID.

Source

pub async fn get_current_user_guilds(&self) -> Result<Vec<Guild>, ClientError>

Returns all guilds the bot is in.

Source

pub async fn get_channel( &self, channel_id: &str, ) -> Result<Channel, ClientError>

Fetches a channel by ID.

Source

pub async fn edit_channel( &self, channel_id: &str, payload: &ChannelCreatePayload, ) -> Result<Channel, ClientError>

Edits a channel. Only the fields you set in the payload will change.

Source

pub async fn delete_channel(&self, channel_id: &str) -> Result<(), ClientError>

Permanently deletes a channel. Can’t be undone.

Source

pub async fn trigger_typing(&self, channel_id: &str) -> Result<(), ClientError>

Triggers the “Bot is typing…” indicator. Lasts ~10 seconds or until the bot sends a message. (I actually haven’t tested this)

Source

pub async fn get_messages( &self, channel_id: &str, query: GetMessagesQuery, ) -> Result<Vec<Message>, ClientError>

Fetches messages from a channel. Use GetMessagesQuery to paginate.

use fluxer::prelude::*;

let query = GetMessagesQuery {
    limit: Some(10),
    ..Default::default()
};
let messages = http.get_messages("channel_id", query).await.unwrap();
Examples found in repository?
examples/bot.rs (line 121)
28    async fn on_message(&self, ctx: Context, msg: Message) {
29        let user_cached = ctx.cache.user(&msg.author.id).await.is_some();
30        let ch_cached   = ctx.cache.channel(msg.channel_id.as_deref().unwrap_or("")).await.is_some();
31        let content_preview = msg.content.as_deref().unwrap_or("").chars().take(60).collect::<String>();
32        let attachments = msg.attachments.as_ref().map(|a| a.len()).unwrap_or(0);
33        let embeds = msg.embeds.as_ref().map(|e| e.len()).unwrap_or(0);
34        println!(
35            "[msg] author={}#{} channel={} guild={} | \"{}\" | attach={} embeds={} | cache: user={} ch={}",
36            msg.author.username,
37            msg.author.discriminator.as_deref().unwrap_or("0"),
38            msg.channel_id.as_deref().unwrap_or("?"),
39            msg.guild_id.as_deref().unwrap_or("DM"),
40            content_preview,
41            attachments,
42            embeds,
43            user_cached,
44            ch_cached,
45        );
46
47        if msg.author.bot.unwrap_or(false) {
48            return;
49        }
50
51        let content = match msg.content.as_deref() {
52            Some(c) => c,
53            None => return,
54        };
55
56        let channel_id = msg.channel_id.as_deref().unwrap_or_default();
57
58        let (cmd, args) = match parse_command(content) {
59            Some(v) => v,
60            None => return,
61        };
62
63        match cmd {
64            "ping" => {
65                let start = Instant::now();
66                let sent = ctx.http.send_message(channel_id, "Pong!").await;
67                let elapsed = start.elapsed().as_millis();
68
69                if let Ok(sent) = sent {
70                    let _ = ctx.http.edit_message(
71                        channel_id,
72                        &sent.id,
73                        &format!("Pong! {}ms", elapsed),
74                    ).await;
75                }
76            }
77
78            "say" => {
79                if args.is_empty() {
80                    let _ = ctx.http.send_message(channel_id, "Say what?").await;
81                    return;
82                }
83                let _ = ctx.http.delete_message(channel_id, &msg.id).await;
84                let _ = ctx.http.send_message(channel_id, args).await;
85            }
86
87            "embed" => {
88                let (title, desc) = match args.split_once('|') {
89                    Some((t, d)) => (t.trim(), d.trim()),
90                    None => {
91                        let _ = ctx.http.send_message(channel_id, "`!embed title | description`").await;
92                        return;
93                    }
94                };
95
96                let embed = EmbedBuilder::new()
97                    .title(title)
98                    .description(desc)
99                    .color(0x5865F2)
100                    .build();
101
102                let _ = ctx.http.send_embed(channel_id, None, vec![embed]).await;
103            }
104
105            "react" => {
106                let _ = ctx.http.add_reaction(channel_id, &msg.id, "❤️").await;
107            }
108
109            "purge" => {
110                let count: u8 = args.parse().unwrap_or(0);
111                if count == 0 || count > 100 {
112                    let _ = ctx.http.send_message(channel_id, "1-100.").await;
113                    return;
114                }
115
116                let query = GetMessagesQuery {
117                    limit: Some(count),
118                    ..Default::default()
119                };
120
121                if let Ok(messages) = ctx.http.get_messages(channel_id, query).await {
122                    let ids: Vec<&str> = messages.iter().map(|m| m.id.as_str()).collect();
123                    let _ = ctx.http.bulk_delete_messages(channel_id, ids).await;
124                }
125            }
126
127            "serverinfo" => {
128                let guild_id = match &msg.guild_id {
129                    Some(id) => id.as_str(),
130                    None => return,
131                };
132
133                if let Ok(guild) = ctx.http.get_guild(guild_id).await {
134                    let name = guild.name.as_deref().unwrap_or("Unknown");
135
136                    let members = ctx.http.get_guild_members(guild_id, Some(1000), None).await
137                        .map(|m| m.len().to_string())
138                        .unwrap_or("?".into());
139
140                    let embed = EmbedBuilder::new()
141                        .title(name)
142                        .field("Members", &members, true)
143                        .color(0x5865F2)
144                        .build();
145
146                    let _ = ctx.http.send_embed(channel_id, None, vec![embed]).await;
147                }
148            }
149
150            _ => {}
151        }
152    }
Source

pub async fn get_message( &self, channel_id: &str, message_id: &str, ) -> Result<Message, ClientError>

Fetches a single message by ID.

Source

pub async fn send_message( &self, channel_id: &str, content: &str, ) -> Result<Message, ClientError>

Sends a text message. For embeds or other options, use send_message_advanced.

Examples found in repository?
examples/voice.rs (line 52)
28    async fn on_message(&self, ctx: Context, msg: Message) {
29        if msg.author.bot.unwrap_or(false) {
30            return;
31        }
32
33        let content = match msg.content.as_deref() {
34            Some(c) => c,
35            None => return,
36        };
37
38        let channel_id = msg.channel_id.as_deref().unwrap_or_default();
39        let guild_id = match msg.guild_id.as_deref() {
40            Some(id) => id,
41            None => return,
42        };
43
44        let (cmd, args) = match parse_command(content) {
45            Some(v) => v,
46            None => return,
47        };
48
49        match cmd {
50            "join" => {
51                if args.is_empty() {
52                    let _ = ctx.http.send_message(channel_id, "`!join <voice_channel_id>`").await;
53                    return;
54                }
55
56                match ctx.join_voice(guild_id, args).await {
57                    Ok(conn) => {
58                        *self.voice.lock().await = Some(conn);
59                        let _ = ctx.http.send_message(channel_id, "Joined.").await;
60                    }
61                    Err(e) => {
62                        let _ = ctx.http.send_message(channel_id, &format!("Failed: {}", e)).await;
63                    }
64                }
65            }
66
67            "leave" => {
68                if let Some(handle) = self.playback.lock().await.take() {
69                    handle.abort();
70                }
71                *self.voice.lock().await = None;
72                let _ = ctx.leave_voice(guild_id).await;
73                let _ = ctx.http.send_message(channel_id, "Left.").await;
74            }
75
76            "play" => {
77                let conn = self.voice.lock().await;
78                let conn = match conn.as_ref() {
79                    Some(c) => c,
80                    None => {
81                        let _ = ctx.http.send_message(channel_id, "Not in a voice channel.").await;
82                        return;
83                    }
84                };
85
86                if let Some(handle) = self.playback.lock().await.take() {
87                    handle.abort();
88                }
89
90                match conn.play_music(AUDIO_FILE, ctx.http.clone(), channel_id.to_string()).await {
91                    Ok(handle) => {
92                        *self.playback.lock().await = Some(handle);
93                        let _ = ctx.http.send_message(channel_id, &format!("Playing `{}`.", AUDIO_FILE)).await;
94                    }
95                    Err(e) => {
96                        let _ = ctx.http.send_message(channel_id, &format!("Failed: {}", e)).await;
97                    }
98                }
99            }
100
101            "stop" => {
102                if let Some(handle) = self.playback.lock().await.take() {
103                    handle.abort();
104                    let _ = ctx.http.send_message(channel_id, "Stopped.").await;
105                } else {
106                    let _ = ctx.http.send_message(channel_id, "Nothing is playing.").await;
107                }
108            }
109
110            _ => {}
111        }
112    }
More examples
Hide additional examples
examples/bot.rs (line 66)
28    async fn on_message(&self, ctx: Context, msg: Message) {
29        let user_cached = ctx.cache.user(&msg.author.id).await.is_some();
30        let ch_cached   = ctx.cache.channel(msg.channel_id.as_deref().unwrap_or("")).await.is_some();
31        let content_preview = msg.content.as_deref().unwrap_or("").chars().take(60).collect::<String>();
32        let attachments = msg.attachments.as_ref().map(|a| a.len()).unwrap_or(0);
33        let embeds = msg.embeds.as_ref().map(|e| e.len()).unwrap_or(0);
34        println!(
35            "[msg] author={}#{} channel={} guild={} | \"{}\" | attach={} embeds={} | cache: user={} ch={}",
36            msg.author.username,
37            msg.author.discriminator.as_deref().unwrap_or("0"),
38            msg.channel_id.as_deref().unwrap_or("?"),
39            msg.guild_id.as_deref().unwrap_or("DM"),
40            content_preview,
41            attachments,
42            embeds,
43            user_cached,
44            ch_cached,
45        );
46
47        if msg.author.bot.unwrap_or(false) {
48            return;
49        }
50
51        let content = match msg.content.as_deref() {
52            Some(c) => c,
53            None => return,
54        };
55
56        let channel_id = msg.channel_id.as_deref().unwrap_or_default();
57
58        let (cmd, args) = match parse_command(content) {
59            Some(v) => v,
60            None => return,
61        };
62
63        match cmd {
64            "ping" => {
65                let start = Instant::now();
66                let sent = ctx.http.send_message(channel_id, "Pong!").await;
67                let elapsed = start.elapsed().as_millis();
68
69                if let Ok(sent) = sent {
70                    let _ = ctx.http.edit_message(
71                        channel_id,
72                        &sent.id,
73                        &format!("Pong! {}ms", elapsed),
74                    ).await;
75                }
76            }
77
78            "say" => {
79                if args.is_empty() {
80                    let _ = ctx.http.send_message(channel_id, "Say what?").await;
81                    return;
82                }
83                let _ = ctx.http.delete_message(channel_id, &msg.id).await;
84                let _ = ctx.http.send_message(channel_id, args).await;
85            }
86
87            "embed" => {
88                let (title, desc) = match args.split_once('|') {
89                    Some((t, d)) => (t.trim(), d.trim()),
90                    None => {
91                        let _ = ctx.http.send_message(channel_id, "`!embed title | description`").await;
92                        return;
93                    }
94                };
95
96                let embed = EmbedBuilder::new()
97                    .title(title)
98                    .description(desc)
99                    .color(0x5865F2)
100                    .build();
101
102                let _ = ctx.http.send_embed(channel_id, None, vec![embed]).await;
103            }
104
105            "react" => {
106                let _ = ctx.http.add_reaction(channel_id, &msg.id, "❤️").await;
107            }
108
109            "purge" => {
110                let count: u8 = args.parse().unwrap_or(0);
111                if count == 0 || count > 100 {
112                    let _ = ctx.http.send_message(channel_id, "1-100.").await;
113                    return;
114                }
115
116                let query = GetMessagesQuery {
117                    limit: Some(count),
118                    ..Default::default()
119                };
120
121                if let Ok(messages) = ctx.http.get_messages(channel_id, query).await {
122                    let ids: Vec<&str> = messages.iter().map(|m| m.id.as_str()).collect();
123                    let _ = ctx.http.bulk_delete_messages(channel_id, ids).await;
124                }
125            }
126
127            "serverinfo" => {
128                let guild_id = match &msg.guild_id {
129                    Some(id) => id.as_str(),
130                    None => return,
131                };
132
133                if let Ok(guild) = ctx.http.get_guild(guild_id).await {
134                    let name = guild.name.as_deref().unwrap_or("Unknown");
135
136                    let members = ctx.http.get_guild_members(guild_id, Some(1000), None).await
137                        .map(|m| m.len().to_string())
138                        .unwrap_or("?".into());
139
140                    let embed = EmbedBuilder::new()
141                        .title(name)
142                        .field("Members", &members, true)
143                        .color(0x5865F2)
144                        .build();
145
146                    let _ = ctx.http.send_embed(channel_id, None, vec![embed]).await;
147                }
148            }
149
150            _ => {}
151        }
152    }
Source

pub async fn send_message_advanced( &self, channel_id: &str, payload: &MessageCreatePayload, ) -> Result<Message, ClientError>

Sends a message with full control over the payload (embeds, TTS, replies, etc).

Source

pub async fn send_embed( &self, channel_id: &str, content: Option<&str>, embeds: Vec<Embed>, ) -> Result<Message, ClientError>

Shorthand for sending embeds. Wraps send_message_advanced.

Examples found in repository?
examples/bot.rs (line 102)
28    async fn on_message(&self, ctx: Context, msg: Message) {
29        let user_cached = ctx.cache.user(&msg.author.id).await.is_some();
30        let ch_cached   = ctx.cache.channel(msg.channel_id.as_deref().unwrap_or("")).await.is_some();
31        let content_preview = msg.content.as_deref().unwrap_or("").chars().take(60).collect::<String>();
32        let attachments = msg.attachments.as_ref().map(|a| a.len()).unwrap_or(0);
33        let embeds = msg.embeds.as_ref().map(|e| e.len()).unwrap_or(0);
34        println!(
35            "[msg] author={}#{} channel={} guild={} | \"{}\" | attach={} embeds={} | cache: user={} ch={}",
36            msg.author.username,
37            msg.author.discriminator.as_deref().unwrap_or("0"),
38            msg.channel_id.as_deref().unwrap_or("?"),
39            msg.guild_id.as_deref().unwrap_or("DM"),
40            content_preview,
41            attachments,
42            embeds,
43            user_cached,
44            ch_cached,
45        );
46
47        if msg.author.bot.unwrap_or(false) {
48            return;
49        }
50
51        let content = match msg.content.as_deref() {
52            Some(c) => c,
53            None => return,
54        };
55
56        let channel_id = msg.channel_id.as_deref().unwrap_or_default();
57
58        let (cmd, args) = match parse_command(content) {
59            Some(v) => v,
60            None => return,
61        };
62
63        match cmd {
64            "ping" => {
65                let start = Instant::now();
66                let sent = ctx.http.send_message(channel_id, "Pong!").await;
67                let elapsed = start.elapsed().as_millis();
68
69                if let Ok(sent) = sent {
70                    let _ = ctx.http.edit_message(
71                        channel_id,
72                        &sent.id,
73                        &format!("Pong! {}ms", elapsed),
74                    ).await;
75                }
76            }
77
78            "say" => {
79                if args.is_empty() {
80                    let _ = ctx.http.send_message(channel_id, "Say what?").await;
81                    return;
82                }
83                let _ = ctx.http.delete_message(channel_id, &msg.id).await;
84                let _ = ctx.http.send_message(channel_id, args).await;
85            }
86
87            "embed" => {
88                let (title, desc) = match args.split_once('|') {
89                    Some((t, d)) => (t.trim(), d.trim()),
90                    None => {
91                        let _ = ctx.http.send_message(channel_id, "`!embed title | description`").await;
92                        return;
93                    }
94                };
95
96                let embed = EmbedBuilder::new()
97                    .title(title)
98                    .description(desc)
99                    .color(0x5865F2)
100                    .build();
101
102                let _ = ctx.http.send_embed(channel_id, None, vec![embed]).await;
103            }
104
105            "react" => {
106                let _ = ctx.http.add_reaction(channel_id, &msg.id, "❤️").await;
107            }
108
109            "purge" => {
110                let count: u8 = args.parse().unwrap_or(0);
111                if count == 0 || count > 100 {
112                    let _ = ctx.http.send_message(channel_id, "1-100.").await;
113                    return;
114                }
115
116                let query = GetMessagesQuery {
117                    limit: Some(count),
118                    ..Default::default()
119                };
120
121                if let Ok(messages) = ctx.http.get_messages(channel_id, query).await {
122                    let ids: Vec<&str> = messages.iter().map(|m| m.id.as_str()).collect();
123                    let _ = ctx.http.bulk_delete_messages(channel_id, ids).await;
124                }
125            }
126
127            "serverinfo" => {
128                let guild_id = match &msg.guild_id {
129                    Some(id) => id.as_str(),
130                    None => return,
131                };
132
133                if let Ok(guild) = ctx.http.get_guild(guild_id).await {
134                    let name = guild.name.as_deref().unwrap_or("Unknown");
135
136                    let members = ctx.http.get_guild_members(guild_id, Some(1000), None).await
137                        .map(|m| m.len().to_string())
138                        .unwrap_or("?".into());
139
140                    let embed = EmbedBuilder::new()
141                        .title(name)
142                        .field("Members", &members, true)
143                        .color(0x5865F2)
144                        .build();
145
146                    let _ = ctx.http.send_embed(channel_id, None, vec![embed]).await;
147                }
148            }
149
150            _ => {}
151        }
152    }
Source

pub async fn edit_message( &self, channel_id: &str, message_id: &str, content: &str, ) -> Result<Message, ClientError>

Edits a message’s content. Bot must be the author.

Examples found in repository?
examples/bot.rs (lines 70-74)
28    async fn on_message(&self, ctx: Context, msg: Message) {
29        let user_cached = ctx.cache.user(&msg.author.id).await.is_some();
30        let ch_cached   = ctx.cache.channel(msg.channel_id.as_deref().unwrap_or("")).await.is_some();
31        let content_preview = msg.content.as_deref().unwrap_or("").chars().take(60).collect::<String>();
32        let attachments = msg.attachments.as_ref().map(|a| a.len()).unwrap_or(0);
33        let embeds = msg.embeds.as_ref().map(|e| e.len()).unwrap_or(0);
34        println!(
35            "[msg] author={}#{} channel={} guild={} | \"{}\" | attach={} embeds={} | cache: user={} ch={}",
36            msg.author.username,
37            msg.author.discriminator.as_deref().unwrap_or("0"),
38            msg.channel_id.as_deref().unwrap_or("?"),
39            msg.guild_id.as_deref().unwrap_or("DM"),
40            content_preview,
41            attachments,
42            embeds,
43            user_cached,
44            ch_cached,
45        );
46
47        if msg.author.bot.unwrap_or(false) {
48            return;
49        }
50
51        let content = match msg.content.as_deref() {
52            Some(c) => c,
53            None => return,
54        };
55
56        let channel_id = msg.channel_id.as_deref().unwrap_or_default();
57
58        let (cmd, args) = match parse_command(content) {
59            Some(v) => v,
60            None => return,
61        };
62
63        match cmd {
64            "ping" => {
65                let start = Instant::now();
66                let sent = ctx.http.send_message(channel_id, "Pong!").await;
67                let elapsed = start.elapsed().as_millis();
68
69                if let Ok(sent) = sent {
70                    let _ = ctx.http.edit_message(
71                        channel_id,
72                        &sent.id,
73                        &format!("Pong! {}ms", elapsed),
74                    ).await;
75                }
76            }
77
78            "say" => {
79                if args.is_empty() {
80                    let _ = ctx.http.send_message(channel_id, "Say what?").await;
81                    return;
82                }
83                let _ = ctx.http.delete_message(channel_id, &msg.id).await;
84                let _ = ctx.http.send_message(channel_id, args).await;
85            }
86
87            "embed" => {
88                let (title, desc) = match args.split_once('|') {
89                    Some((t, d)) => (t.trim(), d.trim()),
90                    None => {
91                        let _ = ctx.http.send_message(channel_id, "`!embed title | description`").await;
92                        return;
93                    }
94                };
95
96                let embed = EmbedBuilder::new()
97                    .title(title)
98                    .description(desc)
99                    .color(0x5865F2)
100                    .build();
101
102                let _ = ctx.http.send_embed(channel_id, None, vec![embed]).await;
103            }
104
105            "react" => {
106                let _ = ctx.http.add_reaction(channel_id, &msg.id, "❤️").await;
107            }
108
109            "purge" => {
110                let count: u8 = args.parse().unwrap_or(0);
111                if count == 0 || count > 100 {
112                    let _ = ctx.http.send_message(channel_id, "1-100.").await;
113                    return;
114                }
115
116                let query = GetMessagesQuery {
117                    limit: Some(count),
118                    ..Default::default()
119                };
120
121                if let Ok(messages) = ctx.http.get_messages(channel_id, query).await {
122                    let ids: Vec<&str> = messages.iter().map(|m| m.id.as_str()).collect();
123                    let _ = ctx.http.bulk_delete_messages(channel_id, ids).await;
124                }
125            }
126
127            "serverinfo" => {
128                let guild_id = match &msg.guild_id {
129                    Some(id) => id.as_str(),
130                    None => return,
131                };
132
133                if let Ok(guild) = ctx.http.get_guild(guild_id).await {
134                    let name = guild.name.as_deref().unwrap_or("Unknown");
135
136                    let members = ctx.http.get_guild_members(guild_id, Some(1000), None).await
137                        .map(|m| m.len().to_string())
138                        .unwrap_or("?".into());
139
140                    let embed = EmbedBuilder::new()
141                        .title(name)
142                        .field("Members", &members, true)
143                        .color(0x5865F2)
144                        .build();
145
146                    let _ = ctx.http.send_embed(channel_id, None, vec![embed]).await;
147                }
148            }
149
150            _ => {}
151        }
152    }
Source

pub async fn edit_message_advanced( &self, channel_id: &str, message_id: &str, payload: &MessageCreatePayload, ) -> Result<Message, ClientError>

Edits a message with full control over the payload.

Source

pub async fn delete_message( &self, channel_id: &str, message_id: &str, ) -> Result<(), ClientError>

Deletes a message. Bot must be the author, or have Manage Messages.

Examples found in repository?
examples/bot.rs (line 83)
28    async fn on_message(&self, ctx: Context, msg: Message) {
29        let user_cached = ctx.cache.user(&msg.author.id).await.is_some();
30        let ch_cached   = ctx.cache.channel(msg.channel_id.as_deref().unwrap_or("")).await.is_some();
31        let content_preview = msg.content.as_deref().unwrap_or("").chars().take(60).collect::<String>();
32        let attachments = msg.attachments.as_ref().map(|a| a.len()).unwrap_or(0);
33        let embeds = msg.embeds.as_ref().map(|e| e.len()).unwrap_or(0);
34        println!(
35            "[msg] author={}#{} channel={} guild={} | \"{}\" | attach={} embeds={} | cache: user={} ch={}",
36            msg.author.username,
37            msg.author.discriminator.as_deref().unwrap_or("0"),
38            msg.channel_id.as_deref().unwrap_or("?"),
39            msg.guild_id.as_deref().unwrap_or("DM"),
40            content_preview,
41            attachments,
42            embeds,
43            user_cached,
44            ch_cached,
45        );
46
47        if msg.author.bot.unwrap_or(false) {
48            return;
49        }
50
51        let content = match msg.content.as_deref() {
52            Some(c) => c,
53            None => return,
54        };
55
56        let channel_id = msg.channel_id.as_deref().unwrap_or_default();
57
58        let (cmd, args) = match parse_command(content) {
59            Some(v) => v,
60            None => return,
61        };
62
63        match cmd {
64            "ping" => {
65                let start = Instant::now();
66                let sent = ctx.http.send_message(channel_id, "Pong!").await;
67                let elapsed = start.elapsed().as_millis();
68
69                if let Ok(sent) = sent {
70                    let _ = ctx.http.edit_message(
71                        channel_id,
72                        &sent.id,
73                        &format!("Pong! {}ms", elapsed),
74                    ).await;
75                }
76            }
77
78            "say" => {
79                if args.is_empty() {
80                    let _ = ctx.http.send_message(channel_id, "Say what?").await;
81                    return;
82                }
83                let _ = ctx.http.delete_message(channel_id, &msg.id).await;
84                let _ = ctx.http.send_message(channel_id, args).await;
85            }
86
87            "embed" => {
88                let (title, desc) = match args.split_once('|') {
89                    Some((t, d)) => (t.trim(), d.trim()),
90                    None => {
91                        let _ = ctx.http.send_message(channel_id, "`!embed title | description`").await;
92                        return;
93                    }
94                };
95
96                let embed = EmbedBuilder::new()
97                    .title(title)
98                    .description(desc)
99                    .color(0x5865F2)
100                    .build();
101
102                let _ = ctx.http.send_embed(channel_id, None, vec![embed]).await;
103            }
104
105            "react" => {
106                let _ = ctx.http.add_reaction(channel_id, &msg.id, "❤️").await;
107            }
108
109            "purge" => {
110                let count: u8 = args.parse().unwrap_or(0);
111                if count == 0 || count > 100 {
112                    let _ = ctx.http.send_message(channel_id, "1-100.").await;
113                    return;
114                }
115
116                let query = GetMessagesQuery {
117                    limit: Some(count),
118                    ..Default::default()
119                };
120
121                if let Ok(messages) = ctx.http.get_messages(channel_id, query).await {
122                    let ids: Vec<&str> = messages.iter().map(|m| m.id.as_str()).collect();
123                    let _ = ctx.http.bulk_delete_messages(channel_id, ids).await;
124                }
125            }
126
127            "serverinfo" => {
128                let guild_id = match &msg.guild_id {
129                    Some(id) => id.as_str(),
130                    None => return,
131                };
132
133                if let Ok(guild) = ctx.http.get_guild(guild_id).await {
134                    let name = guild.name.as_deref().unwrap_or("Unknown");
135
136                    let members = ctx.http.get_guild_members(guild_id, Some(1000), None).await
137                        .map(|m| m.len().to_string())
138                        .unwrap_or("?".into());
139
140                    let embed = EmbedBuilder::new()
141                        .title(name)
142                        .field("Members", &members, true)
143                        .color(0x5865F2)
144                        .build();
145
146                    let _ = ctx.http.send_embed(channel_id, None, vec![embed]).await;
147                }
148            }
149
150            _ => {}
151        }
152    }
Source

pub async fn bulk_delete_messages( &self, channel_id: &str, message_ids: Vec<&str>, ) -> Result<(), ClientError>

Deletes multiple messages at once. Way faster than deleting one by one.

Examples found in repository?
examples/bot.rs (line 123)
28    async fn on_message(&self, ctx: Context, msg: Message) {
29        let user_cached = ctx.cache.user(&msg.author.id).await.is_some();
30        let ch_cached   = ctx.cache.channel(msg.channel_id.as_deref().unwrap_or("")).await.is_some();
31        let content_preview = msg.content.as_deref().unwrap_or("").chars().take(60).collect::<String>();
32        let attachments = msg.attachments.as_ref().map(|a| a.len()).unwrap_or(0);
33        let embeds = msg.embeds.as_ref().map(|e| e.len()).unwrap_or(0);
34        println!(
35            "[msg] author={}#{} channel={} guild={} | \"{}\" | attach={} embeds={} | cache: user={} ch={}",
36            msg.author.username,
37            msg.author.discriminator.as_deref().unwrap_or("0"),
38            msg.channel_id.as_deref().unwrap_or("?"),
39            msg.guild_id.as_deref().unwrap_or("DM"),
40            content_preview,
41            attachments,
42            embeds,
43            user_cached,
44            ch_cached,
45        );
46
47        if msg.author.bot.unwrap_or(false) {
48            return;
49        }
50
51        let content = match msg.content.as_deref() {
52            Some(c) => c,
53            None => return,
54        };
55
56        let channel_id = msg.channel_id.as_deref().unwrap_or_default();
57
58        let (cmd, args) = match parse_command(content) {
59            Some(v) => v,
60            None => return,
61        };
62
63        match cmd {
64            "ping" => {
65                let start = Instant::now();
66                let sent = ctx.http.send_message(channel_id, "Pong!").await;
67                let elapsed = start.elapsed().as_millis();
68
69                if let Ok(sent) = sent {
70                    let _ = ctx.http.edit_message(
71                        channel_id,
72                        &sent.id,
73                        &format!("Pong! {}ms", elapsed),
74                    ).await;
75                }
76            }
77
78            "say" => {
79                if args.is_empty() {
80                    let _ = ctx.http.send_message(channel_id, "Say what?").await;
81                    return;
82                }
83                let _ = ctx.http.delete_message(channel_id, &msg.id).await;
84                let _ = ctx.http.send_message(channel_id, args).await;
85            }
86
87            "embed" => {
88                let (title, desc) = match args.split_once('|') {
89                    Some((t, d)) => (t.trim(), d.trim()),
90                    None => {
91                        let _ = ctx.http.send_message(channel_id, "`!embed title | description`").await;
92                        return;
93                    }
94                };
95
96                let embed = EmbedBuilder::new()
97                    .title(title)
98                    .description(desc)
99                    .color(0x5865F2)
100                    .build();
101
102                let _ = ctx.http.send_embed(channel_id, None, vec![embed]).await;
103            }
104
105            "react" => {
106                let _ = ctx.http.add_reaction(channel_id, &msg.id, "❤️").await;
107            }
108
109            "purge" => {
110                let count: u8 = args.parse().unwrap_or(0);
111                if count == 0 || count > 100 {
112                    let _ = ctx.http.send_message(channel_id, "1-100.").await;
113                    return;
114                }
115
116                let query = GetMessagesQuery {
117                    limit: Some(count),
118                    ..Default::default()
119                };
120
121                if let Ok(messages) = ctx.http.get_messages(channel_id, query).await {
122                    let ids: Vec<&str> = messages.iter().map(|m| m.id.as_str()).collect();
123                    let _ = ctx.http.bulk_delete_messages(channel_id, ids).await;
124                }
125            }
126
127            "serverinfo" => {
128                let guild_id = match &msg.guild_id {
129                    Some(id) => id.as_str(),
130                    None => return,
131                };
132
133                if let Ok(guild) = ctx.http.get_guild(guild_id).await {
134                    let name = guild.name.as_deref().unwrap_or("Unknown");
135
136                    let members = ctx.http.get_guild_members(guild_id, Some(1000), None).await
137                        .map(|m| m.len().to_string())
138                        .unwrap_or("?".into());
139
140                    let embed = EmbedBuilder::new()
141                        .title(name)
142                        .field("Members", &members, true)
143                        .color(0x5865F2)
144                        .build();
145
146                    let _ = ctx.http.send_embed(channel_id, None, vec![embed]).await;
147                }
148            }
149
150            _ => {}
151        }
152    }
Source

pub async fn add_reaction( &self, channel_id: &str, message_id: &str, emoji: &str, ) -> Result<(), ClientError>

Reacts to a message as the bot. emoji should be a unicode emoji like "👍" or a custom emoji in name:id format. You can use Emoji::to_reaction_string to get the right format.

Examples found in repository?
examples/bot.rs (line 106)
28    async fn on_message(&self, ctx: Context, msg: Message) {
29        let user_cached = ctx.cache.user(&msg.author.id).await.is_some();
30        let ch_cached   = ctx.cache.channel(msg.channel_id.as_deref().unwrap_or("")).await.is_some();
31        let content_preview = msg.content.as_deref().unwrap_or("").chars().take(60).collect::<String>();
32        let attachments = msg.attachments.as_ref().map(|a| a.len()).unwrap_or(0);
33        let embeds = msg.embeds.as_ref().map(|e| e.len()).unwrap_or(0);
34        println!(
35            "[msg] author={}#{} channel={} guild={} | \"{}\" | attach={} embeds={} | cache: user={} ch={}",
36            msg.author.username,
37            msg.author.discriminator.as_deref().unwrap_or("0"),
38            msg.channel_id.as_deref().unwrap_or("?"),
39            msg.guild_id.as_deref().unwrap_or("DM"),
40            content_preview,
41            attachments,
42            embeds,
43            user_cached,
44            ch_cached,
45        );
46
47        if msg.author.bot.unwrap_or(false) {
48            return;
49        }
50
51        let content = match msg.content.as_deref() {
52            Some(c) => c,
53            None => return,
54        };
55
56        let channel_id = msg.channel_id.as_deref().unwrap_or_default();
57
58        let (cmd, args) = match parse_command(content) {
59            Some(v) => v,
60            None => return,
61        };
62
63        match cmd {
64            "ping" => {
65                let start = Instant::now();
66                let sent = ctx.http.send_message(channel_id, "Pong!").await;
67                let elapsed = start.elapsed().as_millis();
68
69                if let Ok(sent) = sent {
70                    let _ = ctx.http.edit_message(
71                        channel_id,
72                        &sent.id,
73                        &format!("Pong! {}ms", elapsed),
74                    ).await;
75                }
76            }
77
78            "say" => {
79                if args.is_empty() {
80                    let _ = ctx.http.send_message(channel_id, "Say what?").await;
81                    return;
82                }
83                let _ = ctx.http.delete_message(channel_id, &msg.id).await;
84                let _ = ctx.http.send_message(channel_id, args).await;
85            }
86
87            "embed" => {
88                let (title, desc) = match args.split_once('|') {
89                    Some((t, d)) => (t.trim(), d.trim()),
90                    None => {
91                        let _ = ctx.http.send_message(channel_id, "`!embed title | description`").await;
92                        return;
93                    }
94                };
95
96                let embed = EmbedBuilder::new()
97                    .title(title)
98                    .description(desc)
99                    .color(0x5865F2)
100                    .build();
101
102                let _ = ctx.http.send_embed(channel_id, None, vec![embed]).await;
103            }
104
105            "react" => {
106                let _ = ctx.http.add_reaction(channel_id, &msg.id, "❤️").await;
107            }
108
109            "purge" => {
110                let count: u8 = args.parse().unwrap_or(0);
111                if count == 0 || count > 100 {
112                    let _ = ctx.http.send_message(channel_id, "1-100.").await;
113                    return;
114                }
115
116                let query = GetMessagesQuery {
117                    limit: Some(count),
118                    ..Default::default()
119                };
120
121                if let Ok(messages) = ctx.http.get_messages(channel_id, query).await {
122                    let ids: Vec<&str> = messages.iter().map(|m| m.id.as_str()).collect();
123                    let _ = ctx.http.bulk_delete_messages(channel_id, ids).await;
124                }
125            }
126
127            "serverinfo" => {
128                let guild_id = match &msg.guild_id {
129                    Some(id) => id.as_str(),
130                    None => return,
131                };
132
133                if let Ok(guild) = ctx.http.get_guild(guild_id).await {
134                    let name = guild.name.as_deref().unwrap_or("Unknown");
135
136                    let members = ctx.http.get_guild_members(guild_id, Some(1000), None).await
137                        .map(|m| m.len().to_string())
138                        .unwrap_or("?".into());
139
140                    let embed = EmbedBuilder::new()
141                        .title(name)
142                        .field("Members", &members, true)
143                        .color(0x5865F2)
144                        .build();
145
146                    let _ = ctx.http.send_embed(channel_id, None, vec![embed]).await;
147                }
148            }
149
150            _ => {}
151        }
152    }
Source

pub async fn remove_own_reaction( &self, channel_id: &str, message_id: &str, emoji: &str, ) -> Result<(), ClientError>

Removes the bot’s own reaction from a message.

Source

pub async fn remove_user_reaction( &self, channel_id: &str, message_id: &str, emoji: &str, user_id: &str, ) -> Result<(), ClientError>

Removes someone else’s reaction. Needs Manage Messages permission.

Source

pub async fn get_reactions( &self, channel_id: &str, message_id: &str, emoji: &str, ) -> Result<Vec<User>, ClientError>

Gets the list of users who reacted with a specific emoji.

Source

pub async fn clear_reactions( &self, channel_id: &str, message_id: &str, ) -> Result<(), ClientError>

Removes all reactions from a message. Needs Manage Messages.

Source

pub async fn clear_reactions_for_emoji( &self, channel_id: &str, message_id: &str, emoji: &str, ) -> Result<(), ClientError>

Removes all reactions for a specific emoji. Needs Manage Messages.

Source

pub async fn get_pins( &self, channel_id: &str, ) -> Result<PinsResponse, ClientError>

Fetches pinned messages in a channel.

Source

pub async fn pin_message( &self, channel_id: &str, message_id: &str, ) -> Result<(), ClientError>

Pins a message. Needs Manage Messages.

Source

pub async fn unpin_message( &self, channel_id: &str, message_id: &str, ) -> Result<(), ClientError>

Unpins a message. Needs Manage Messages.

Source

pub async fn get_invite(&self, invite_code: &str) -> Result<Invite, ClientError>

Fetches an invite by code. Includes approximate member counts.

Source

pub async fn create_invite( &self, channel_id: &str, payload: &CreateInvitePayload, ) -> Result<Invite, ClientError>

Creates an invite for a channel.

Source

pub async fn delete_invite(&self, invite_code: &str) -> Result<(), ClientError>

Deletes an invite by code.

Source

pub async fn get_channel_invites( &self, channel_id: &str, ) -> Result<Vec<Invite>, ClientError>

Returns all active invites for a channel.

Source

pub async fn get_guild_invites( &self, guild_id: &str, ) -> Result<Vec<Invite>, ClientError>

Returns all active invites for a guild.

Source

pub async fn get_guild(&self, guild_id: &str) -> Result<Guild, ClientError>

Fetches a guild by ID.

Examples found in repository?
examples/bot.rs (line 133)
28    async fn on_message(&self, ctx: Context, msg: Message) {
29        let user_cached = ctx.cache.user(&msg.author.id).await.is_some();
30        let ch_cached   = ctx.cache.channel(msg.channel_id.as_deref().unwrap_or("")).await.is_some();
31        let content_preview = msg.content.as_deref().unwrap_or("").chars().take(60).collect::<String>();
32        let attachments = msg.attachments.as_ref().map(|a| a.len()).unwrap_or(0);
33        let embeds = msg.embeds.as_ref().map(|e| e.len()).unwrap_or(0);
34        println!(
35            "[msg] author={}#{} channel={} guild={} | \"{}\" | attach={} embeds={} | cache: user={} ch={}",
36            msg.author.username,
37            msg.author.discriminator.as_deref().unwrap_or("0"),
38            msg.channel_id.as_deref().unwrap_or("?"),
39            msg.guild_id.as_deref().unwrap_or("DM"),
40            content_preview,
41            attachments,
42            embeds,
43            user_cached,
44            ch_cached,
45        );
46
47        if msg.author.bot.unwrap_or(false) {
48            return;
49        }
50
51        let content = match msg.content.as_deref() {
52            Some(c) => c,
53            None => return,
54        };
55
56        let channel_id = msg.channel_id.as_deref().unwrap_or_default();
57
58        let (cmd, args) = match parse_command(content) {
59            Some(v) => v,
60            None => return,
61        };
62
63        match cmd {
64            "ping" => {
65                let start = Instant::now();
66                let sent = ctx.http.send_message(channel_id, "Pong!").await;
67                let elapsed = start.elapsed().as_millis();
68
69                if let Ok(sent) = sent {
70                    let _ = ctx.http.edit_message(
71                        channel_id,
72                        &sent.id,
73                        &format!("Pong! {}ms", elapsed),
74                    ).await;
75                }
76            }
77
78            "say" => {
79                if args.is_empty() {
80                    let _ = ctx.http.send_message(channel_id, "Say what?").await;
81                    return;
82                }
83                let _ = ctx.http.delete_message(channel_id, &msg.id).await;
84                let _ = ctx.http.send_message(channel_id, args).await;
85            }
86
87            "embed" => {
88                let (title, desc) = match args.split_once('|') {
89                    Some((t, d)) => (t.trim(), d.trim()),
90                    None => {
91                        let _ = ctx.http.send_message(channel_id, "`!embed title | description`").await;
92                        return;
93                    }
94                };
95
96                let embed = EmbedBuilder::new()
97                    .title(title)
98                    .description(desc)
99                    .color(0x5865F2)
100                    .build();
101
102                let _ = ctx.http.send_embed(channel_id, None, vec![embed]).await;
103            }
104
105            "react" => {
106                let _ = ctx.http.add_reaction(channel_id, &msg.id, "❤️").await;
107            }
108
109            "purge" => {
110                let count: u8 = args.parse().unwrap_or(0);
111                if count == 0 || count > 100 {
112                    let _ = ctx.http.send_message(channel_id, "1-100.").await;
113                    return;
114                }
115
116                let query = GetMessagesQuery {
117                    limit: Some(count),
118                    ..Default::default()
119                };
120
121                if let Ok(messages) = ctx.http.get_messages(channel_id, query).await {
122                    let ids: Vec<&str> = messages.iter().map(|m| m.id.as_str()).collect();
123                    let _ = ctx.http.bulk_delete_messages(channel_id, ids).await;
124                }
125            }
126
127            "serverinfo" => {
128                let guild_id = match &msg.guild_id {
129                    Some(id) => id.as_str(),
130                    None => return,
131                };
132
133                if let Ok(guild) = ctx.http.get_guild(guild_id).await {
134                    let name = guild.name.as_deref().unwrap_or("Unknown");
135
136                    let members = ctx.http.get_guild_members(guild_id, Some(1000), None).await
137                        .map(|m| m.len().to_string())
138                        .unwrap_or("?".into());
139
140                    let embed = EmbedBuilder::new()
141                        .title(name)
142                        .field("Members", &members, true)
143                        .color(0x5865F2)
144                        .build();
145
146                    let _ = ctx.http.send_embed(channel_id, None, vec![embed]).await;
147                }
148            }
149
150            _ => {}
151        }
152    }
Source

pub async fn edit_guild( &self, guild_id: &str, payload: &EditGuildPayload, ) -> Result<Guild, ClientError>

Edits guild settings. Only fields you set in the payload will change.

Source

pub async fn delete_guild(&self, guild_id: &str) -> Result<(), ClientError>

Permanently deletes a guild. The bot must be the owner. (not tested)

Source

pub async fn get_guild_channels( &self, guild_id: &str, ) -> Result<Vec<Channel>, ClientError>

Returns all channels in a guild.

Source

pub async fn create_channel( &self, guild_id: &str, payload: &ChannelCreatePayload, ) -> Result<Channel, ClientError>

Creates a channel in a guild. You need at least name in the payload.

Source

pub async fn get_guild_member( &self, guild_id: &str, user_id: &str, ) -> Result<Member, ClientError>

Fetches a single guild member.

Source

pub async fn get_guild_members( &self, guild_id: &str, limit: Option<u16>, after: Option<&str>, ) -> Result<Vec<Member>, ClientError>

Fetches guild members. limit caps at 1000, after is a user ID for pagination.

Examples found in repository?
examples/bot.rs (line 136)
28    async fn on_message(&self, ctx: Context, msg: Message) {
29        let user_cached = ctx.cache.user(&msg.author.id).await.is_some();
30        let ch_cached   = ctx.cache.channel(msg.channel_id.as_deref().unwrap_or("")).await.is_some();
31        let content_preview = msg.content.as_deref().unwrap_or("").chars().take(60).collect::<String>();
32        let attachments = msg.attachments.as_ref().map(|a| a.len()).unwrap_or(0);
33        let embeds = msg.embeds.as_ref().map(|e| e.len()).unwrap_or(0);
34        println!(
35            "[msg] author={}#{} channel={} guild={} | \"{}\" | attach={} embeds={} | cache: user={} ch={}",
36            msg.author.username,
37            msg.author.discriminator.as_deref().unwrap_or("0"),
38            msg.channel_id.as_deref().unwrap_or("?"),
39            msg.guild_id.as_deref().unwrap_or("DM"),
40            content_preview,
41            attachments,
42            embeds,
43            user_cached,
44            ch_cached,
45        );
46
47        if msg.author.bot.unwrap_or(false) {
48            return;
49        }
50
51        let content = match msg.content.as_deref() {
52            Some(c) => c,
53            None => return,
54        };
55
56        let channel_id = msg.channel_id.as_deref().unwrap_or_default();
57
58        let (cmd, args) = match parse_command(content) {
59            Some(v) => v,
60            None => return,
61        };
62
63        match cmd {
64            "ping" => {
65                let start = Instant::now();
66                let sent = ctx.http.send_message(channel_id, "Pong!").await;
67                let elapsed = start.elapsed().as_millis();
68
69                if let Ok(sent) = sent {
70                    let _ = ctx.http.edit_message(
71                        channel_id,
72                        &sent.id,
73                        &format!("Pong! {}ms", elapsed),
74                    ).await;
75                }
76            }
77
78            "say" => {
79                if args.is_empty() {
80                    let _ = ctx.http.send_message(channel_id, "Say what?").await;
81                    return;
82                }
83                let _ = ctx.http.delete_message(channel_id, &msg.id).await;
84                let _ = ctx.http.send_message(channel_id, args).await;
85            }
86
87            "embed" => {
88                let (title, desc) = match args.split_once('|') {
89                    Some((t, d)) => (t.trim(), d.trim()),
90                    None => {
91                        let _ = ctx.http.send_message(channel_id, "`!embed title | description`").await;
92                        return;
93                    }
94                };
95
96                let embed = EmbedBuilder::new()
97                    .title(title)
98                    .description(desc)
99                    .color(0x5865F2)
100                    .build();
101
102                let _ = ctx.http.send_embed(channel_id, None, vec![embed]).await;
103            }
104
105            "react" => {
106                let _ = ctx.http.add_reaction(channel_id, &msg.id, "❤️").await;
107            }
108
109            "purge" => {
110                let count: u8 = args.parse().unwrap_or(0);
111                if count == 0 || count > 100 {
112                    let _ = ctx.http.send_message(channel_id, "1-100.").await;
113                    return;
114                }
115
116                let query = GetMessagesQuery {
117                    limit: Some(count),
118                    ..Default::default()
119                };
120
121                if let Ok(messages) = ctx.http.get_messages(channel_id, query).await {
122                    let ids: Vec<&str> = messages.iter().map(|m| m.id.as_str()).collect();
123                    let _ = ctx.http.bulk_delete_messages(channel_id, ids).await;
124                }
125            }
126
127            "serverinfo" => {
128                let guild_id = match &msg.guild_id {
129                    Some(id) => id.as_str(),
130                    None => return,
131                };
132
133                if let Ok(guild) = ctx.http.get_guild(guild_id).await {
134                    let name = guild.name.as_deref().unwrap_or("Unknown");
135
136                    let members = ctx.http.get_guild_members(guild_id, Some(1000), None).await
137                        .map(|m| m.len().to_string())
138                        .unwrap_or("?".into());
139
140                    let embed = EmbedBuilder::new()
141                        .title(name)
142                        .field("Members", &members, true)
143                        .color(0x5865F2)
144                        .build();
145
146                    let _ = ctx.http.send_embed(channel_id, None, vec![embed]).await;
147                }
148            }
149
150            _ => {}
151        }
152    }
Source

pub async fn kick_member( &self, guild_id: &str, user_id: &str, ) -> Result<(), ClientError>

Kicks a member from the guild.

Source

pub async fn edit_member( &self, guild_id: &str, user_id: &str, payload: &EditMemberPayload, ) -> Result<Member, ClientError>

Edits a member’s properties. To clear a nullable field like nick, set it to Some(None).

Source

pub async fn ban_member( &self, guild_id: &str, user_id: &str, reason: &str, ) -> Result<(), ClientError>

Bans a member. reason is stored in the audit log.

Source

pub async fn unban_member( &self, guild_id: &str, user_id: &str, ) -> Result<(), ClientError>

Removes a ban.

Source

pub async fn get_guild_bans( &self, guild_id: &str, ) -> Result<Vec<Value>, ClientError>

Returns the guild’s ban list.

Source

pub async fn get_guild_roles( &self, guild_id: &str, ) -> Result<Vec<Role>, ClientError>

Returns all roles in a guild.

Source

pub async fn create_role( &self, guild_id: &str, payload: &CreateRolePayload, ) -> Result<Role, ClientError>

Creates a new role in a guild.

Source

pub async fn edit_role( &self, guild_id: &str, role_id: &str, payload: &EditRolePayload, ) -> Result<Role, ClientError>

Edits a role’s properties.

Source

pub async fn delete_role( &self, guild_id: &str, role_id: &str, ) -> Result<(), ClientError>

Deletes a role.

Source

pub async fn get_guild_emojis( &self, guild_id: &str, ) -> Result<Vec<Emoji>, ClientError>

Returns all custom emojis in a guild.

Source

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

Deletes a custom emoji from a guild.

Source

pub async fn get_channel_webhooks( &self, channel_id: &str, ) -> Result<Vec<Webhook>, ClientError>

Returns all webhooks for a channel.

Source

pub async fn get_guild_webhooks( &self, guild_id: &str, ) -> Result<Vec<Webhook>, ClientError>

Returns all webhooks for a guild.

Source

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

avatar should be a data URI if provided.

Source

pub async fn delete_webhook(&self, webhook_id: &str) -> Result<(), ClientError>

Deletes a webhook.

Source

pub async fn execute_webhook( &self, webhook_id: &str, webhook_token: &str, payload: &WebhookExecutePayload, ) -> Result<Option<Message>, ClientError>

Executes a webhook (sends a message through it). Uses wait=true so the response includes the full message object.

Auto Trait Implementations§

§

impl Freeze for Http

§

impl !RefUnwindSafe for Http

§

impl Send for Http

§

impl Sync for Http

§

impl Unpin for Http

§

impl UnsafeUnpin for Http

§

impl !UnwindSafe for Http

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> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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