Automate is a low level and asynchronous rust library for interacting with the Discord API.
Automate currently only works with Rust nightly starting from 1.45
. The usually tested version and the one used in CI is
nightly-2020-08-03
, you can use more recent versions but please swich back to this version
if you get a compile error. Refer to rust edition guide
to learn how to switch to rust nightly.
In order to use Automate in your project, add the following line to your Cargo.toml
:
[dependencies]
automate = "0.4.0"
You can then write the following in your main.rs
. This simple example will respond Hello ! to any
user posting a message in any channel while ignoring messages from bots.
In order for this example to work, you need to define the DISCORD_API_TOKEN
environment variable. You can create a
bot and generate a token on Discord's developers portal.
#[macro_use]
extern crate automate;
use automate::{Error, Configuration, Context, Automate};
use automate::gateway::MessageCreateDispatch;
use automate::http::CreateMessage;
#[listener]
async fn say_hello(ctx: &mut Context, data: &MessageCreateDispatch) -> Result<(), Error> {
let message = &data.0;
if message.author.id != ctx.bot.id {
let content = Some(format!("Hello {}!", message.author.username));
ctx.create_message(message.channel_id, CreateMessage {
content,
..Default::default()
}).await?;
}
Ok(())
}
fn main() {
let config = Configuration::from_env("DISCORD_API_TOKEN")
.register(stateless!(say_hello));
Automate::launch(config)
}
For examples with more details, see in the examples
folder. You can also refer to the documentation.
While mature enough to make text bots, Automate is still missing some important features which will be implemented soon such as :
- Caching system: necessary to avoid making API calls each time you need information about a member or a guild. You can still implement it manually, see the levels example.
- Voice: it is possible to interact with members in voice channels (kicking, muting, deafening them...) but it is not possible to make the bot join a channel and receive or send sound.
- More examples: not a feature but necessary to properly show how the library works, feel free to make pull request if you want to submit one :)
Any kind of contribution is welcome, from issues to pull requests. For major changes, please open an issue first to discuss what you would like to change. Please make sure to update documentation as appropriate.
If you need support, want to report a bug or contribute, you can join the library's discord server using this invite https://discord.gg/invite/PGGYXy2
Licensed under the MIT license.