4 releases (2 breaking)

0.3.0 Apr 8, 2023
0.2.1 Jun 20, 2022
0.2.0 Feb 18, 2022
0.1.0 Oct 4, 2021

#15 in #slash-command

41 downloads per month

MIT/Apache

245KB
4K SLoC

Slashook

A webhook-based Discord slash command library.

This is a WIP project. Please note breaking changes can occur within minor releases until version 1.0.0.

Things to be done

  • REST methods for full API coverage
  • Utility methods
  • More validation library-side
  • Tests and benchmarks

The gateway (and by extension voice) functionality is out of scope for this project.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


lib.rs:

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.

Dependencies

~25–64MB
~1M SLoC