Skip to content

Commit

Permalink
Fixed example
Browse files Browse the repository at this point in the history
  • Loading branch information
AS1100K committed Oct 13, 2024
1 parent e789588 commit 1a5f81b
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ 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`
Expand All @@ -30,9 +32,11 @@ use serde_json::json;
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;
let message_content = &event.new_message.content;

println!("Got a new message -> {}", message_content);

Expand All @@ -41,10 +45,15 @@ fn handle_chat_relay(
// ...

// Send a message to discord
let channel_id = ChannelId::new(7);
ctx.http.send_message(channel_id, Vec::new(), &json({
"content": "Hello from bevy-discord"
})).await.unwrap();
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();
});
}
}
```
Expand Down

0 comments on commit 1a5f81b

Please sign in to comment.