Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mbenoukaiss/automate

An asynchronous library to interact with Discord API
https://github.com/mbenoukaiss/automate

async bot discord-api rust

Last synced: about 2 months ago
JSON representation

An asynchronous library to interact with Discord API

Awesome Lists containing this project

README

        

# Automate   [GitHub Workflow Status](https://github.com/mbenoukaiss/automate/actions) [Crates.io](https://crates.io/crates/automate) [Discord](https://discord.gg/invite/PGGYXy2) [Documentation](https://docs.rs/automate) [License](https://github.com/mbenoukaiss/automate/blob/master/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 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](https://doc.rust-lang.org/edition-guide/rust-2018/rustup-for-managing-rust-versions.html)
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](https://discordapp.com/developers/applications/).

```rust
#[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](https://docs.rs/automate).

# 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](examples/levels.rs).
- **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](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.

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

# License
Licensed under the [MIT license](LICENSE).