#discord #native #async #discord-api #library #async-api #api

yanked railgun

使用 Rust 编写的支持原生 async/await 的 Discord API 库

0.1.2 2019年12月27日
0.1.1 2019年12月27日
0.1.0 2019年12月27日

#61 in #discord-api

MIT 许可证

12KB
294 lines

railgun

使用 Rust 编写的基于原生 async/await 的 Discord API 库

索引

简介

无聊。在 Rust 中摆弄原生 async/await,想边写 Discord 库边试试。

状态

MVP

  • REST API 覆盖率
  • WebSocket 网关覆盖率
  • 语音支持?
  • 通过过程宏的事件监听器

示例

免责声明!下面显示的示例是库最终希望看起来的样子。

乒乓

use {
    std::{env, io},
    railgun::{Client, register}
}

#[railgun::event(on = "MESSAGE_CREATE")]
async fn on_message(client: &Client, message: Message) -> Option<railgun::Error> {
    println!("{:?}", message);

    if message.content.starts_with("?ping") {
        client.send(&message.channel, "Pong!").await?;
    }

    None
}

#[tokio::main]
async fn main() {
    Client::default()
        .mount(register![on_message])
        .run(env::var("DISCORD_TOKEN")).await
        .expect("Could not start discord client.");
}

依赖

~3–7.5MB
~170K SLoC