Crate slashook

source ·
Expand description

A webhook-based Discord slash command library

This library focuses on the use of a web server to receive command 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 };

#[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?;
  }

  let mut client = Client::new(config);
  client.register_command(ping);
  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 on the Developer Portal.

Take a look at CommandInput and CommandResponder for the values and functions you have at your disposal in your functions.

Re-exports

  • pub use rocket::tokio;
  • pub use chrono;

Modules

  • Structs used in creating commands
  • Discord rest api handling
  • Various structs for working with Discord’s objects

Structs

  • The entry point of the library
  • Configuration options for the client

Attribute Macros

  • A macro that turns a function to a Command
  • Sets up an async runtime