#discord #api #async

nightly automate

An asynchronous library to interact with Discord API and make bots

9 releases

✓ Uses Rust 2018 edition

0.3.1 Apr 25, 2020
0.3.0 Mar 27, 2020
0.2.1 Feb 29, 2020
0.1.4 Jan 17, 2020
0.1.3 Nov 29, 2019

#107 in Asynchronous

Download history 9/week @ 2020-03-12 38/week @ 2020-03-19 31/week @ 2020-03-26 3/week @ 2020-04-02 32/week @ 2020-04-09 29/week @ 2020-04-16 19/week @ 2020-04-23 3/week @ 2020-04-30 1/week @ 2020-05-07 13/week @ 2020-05-21 18/week @ 2020-05-28 21/week @ 2020-06-04 2/week @ 2020-06-25

84 downloads per month

MIT license

220KB
4K SLoC

Automate   GitHub Workflow Status Crates.io GitHub issues License

Automate is a low level and asynchronous rust library for interacting with the Discord API

Getting started

Automate currently only works with Rust nightly. The tested version and the one used in CI is nightly-2020-01-31, 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.3.1"

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.

Upcoming features

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 :)

Contributing

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.

License

Licensed under the MIT license.

Dependencies

~11MB
~227K SLoC