Crates.io | automate-derive |
lib.rs | automate-derive |
version | 0.4.0 |
source | src |
created_at | 2019-11-15 16:39:52.865529 |
updated_at | 2020-10-11 14:38:59.608351 |
description | Derive macros for the automate library |
homepage | |
repository | https://github.com/mbenoukaiss/automate |
max_upload_size | |
id | 181546 |
size | 51,210 |
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 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 :
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.