5 releases (3 breaking)
0.4.0 | Jun 14, 2024 |
---|---|
0.3.0 | Apr 8, 2023 |
0.2.1 | Jun 20, 2022 |
0.2.0 | Feb 18, 2022 |
0.1.0 | Oct 4, 2021 |
#928 in Web programming
51 downloads per month
290KB
4.5K
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
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
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
~24–57MB
~1M SLoC