10个版本

0.0.10 2023年9月10日
0.0.9 2023年7月14日
0.0.8 2023年6月7日
0.0.4 2023年5月31日
0.0.3 2023年3月27日

#1594 in 网页编程

Download history 5/week @ 2024-03-12 1/week @ 2024-03-26 5/week @ 2024-04-02

52 每月下载次数

MIT 许可证

150KB
2.5K SLoC

adiscord

基于Rust的API和网关Discord包装器

安装

使用包管理器 cargo 安装 adiscord。

API安装

cargo add adiscord
cargo add tokio --features rt-multi-thread

网关安装

cargo add adiscord --features gateway
cargo add adiscord_intents
cargo add tokio --features rt-multi-thread

用法

(以下示例需要安装 dotenv 以使用 .env 文件。以下命令 cargo add dotenv)

使用API的示例

use adiscord::Client;
use dotenv_codegen::dotenv;

#[tokio::main]
async fn main() {
    // Client initialisation
    let mut client = Client::new(dotenv!("TOKEN"));

    // Recover a server from its ID
    match client.guild.get("1089521338286342195").await {
        Ok(guild) => println!("{:?}", guild.name),
        Err(error) => println!("{:?}", error),
    };
}

使用网关的示例

use adiscord::Client;
use adiscord_intents::Intent;
use dotenv_codegen::dotenv;

#[tokio::main]
async fn main() {
    // Client initialisation
    let mut client = Client::new(dotenv!("TOKEN"));

    // Receive heartbeat messages, delete this line if you do not wish to do so
    client.set_heartbeat_ack(true);

    // Send all the permissions you need from your bot to discord
    client.all_intents();

    // The ready event will be launched once your bot is connected
    client.on_ready(|ready| {
        println!("{:?}", ready);
    });
}

贡献

欢迎Pull requests。对于重大更改,请先创建一个问题来讨论您想要更改的内容。

许可证

MIT

依赖关系

~3–20MB
~289K SLoC