Expand description
A webhook-based Discord slash command library
This library focuses on the use of a web server to receive commands and events with the interaction system instead of the traditional gateway websocket. Scaling can be performed using any load balancing solution and no guild count based sharding is required.
§Usage
First, head over to the Discord Developer Portal and grab your application’s public key and optionally a bot token, client id and/or client secret.
Here’s a simple example to get you started:
#[macro_use] extern crate slashook;
use slashook::{ Client, Config };
use slashook::commands::{ CommandInput, CommandResponder };
use slashook::events::{ EventInput, EventType };
use slashook::structs::events::ApplicationAuthorizedEventData;
#[slashook::main]
async fn main() {
let config = Config {
public_key: String::from("your_public_key"),
bot_token: Some(String::from("your.bot.token")),
client_id: Some(String::from("your_client_id")),
..Default::default()
};
#[command(name = "ping", description = "pong")]
fn ping(input: CommandInput, res: CommandResponder) {
res.send_message("Pong!").await?;
}
#[event(EventType::APPLICATION_AUTHORIZED)]
fn authorized(event: EventInput, data: ApplicationAuthorizedEventData) {
event.ack().await?;
println!("Authorized by {} at {}", data.user.username, event.timestamp);
}
let mut client = Client::new(config);
client.register_command(ping);
client.register_event(authorized);
client.sync_commands().await;
client.start().await;
}
Your bot will now be listening on http://0.0.0.0:3000/
. See Config for IP and port options.
You may now route it through a reverse proxy and set your interaction url with route /
and event url with route /events
on the Developer Portal.
Take a look at CommandInput and CommandResponder for the values and functions you have at your disposal in your command functions. Check out EventInput for data available in every event as well as how to acknowledge them and EventData for the available data types for different EventTypes.
Re-exports§
Modules§
- commands
- Structs used in creating commands
- events
- Structs used in creating event handlers
- rest
- Discord rest api handling
- structs
- Various structs for working with Discord’s objects