bevy-discord 0.2.2

A bevy plugin for sending and receiving discord messages.
Documentation

Bevy Discord Plugin

GitHub License Crates.io Version CI

A very simple, bevy plugin that let you send and receive messages through bevy events.

Usage

Add bevy-discord as your dependency:

$ cargo add bevy-discord --features full

Example Usage:

use bevy_ecs::prelude::*;
use bevy_discord::bot::{ 
    events::BMessage,
    DiscordBotRes,
    serenity::model::id::ChannelId
};
use bevy_discord::runtime::tokio_runtime;
use serde_json::json;

// Make sure to add [bevy_discord::bot::DiscordBotPlugin] to the `App`

#[allow(clippy::complexity)]
fn handle_chat_relay(
    // Event emitted when an message is received on discord
    mut events: EventReader<BMessage>,
    // Discord Res
    discord_bot_res: Res<DiscordBotRes>
) {
    for event in events.read() {
        let message_content = &event.new_message.content;
        
        println!("Got a new message -> {}", message_content);

        // ...
        // Using this message as some sort of command
        // ...
        
        // Send a message to discord
        let http = discord_bot_res.get_http().unwrap();

        tokio_runtime().spawn(async move {
            let channel_id = ChannelId::new(7);

            http.send_message(channel_id, Vec::new(), &json!({
                "content": "Hello from bevy-discord"
            })).await.unwrap();
        });
    }
}

If you want real examples then, it's worth checking out crate aether-core, although it is archived now.

Features

This crate using powerful cargo features.

Feature Information
webhook Uses discord webhooks, using this you can only send messages.
bot This uses serenity behind the scenes and you can create awesome discord bots with it.

both features are comes under full feature.

Not Supported Features

Currently, this crate is under development and there are features that are supported by discord and serenity but not supported by us.

Feature Module
voice bot
attachments webhook