tried to spawn a thread for the bot to run freely
This commit is contained in:
parent
5b5f4fb958
commit
2317a41bba
15
src/bot.rs
15
src/bot.rs
|
@ -26,14 +26,19 @@ impl EventHandler for Handler {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn start_discord_bot() -> Result<Client, String> {
|
||||
let mut client = Client::builder(token::TOKEN)
|
||||
pub async fn start_discord_bot() {
|
||||
let maybe_client = Client::builder(token::TOKEN)
|
||||
.event_handler(Handler)
|
||||
.await
|
||||
.map_err(|why| format!("Client error: {:?}", why))?;
|
||||
.map_err(|why| format!("Client error: {:?}", why));
|
||||
|
||||
if let Ok(mut client) = maybe_client {
|
||||
if let Err(why) = client.start().await {
|
||||
return Err(format!("Client error: {:?}", why));
|
||||
eprintln!("Client error: {:?}", why);
|
||||
return
|
||||
}
|
||||
} else {
|
||||
eprintln!("No Client");
|
||||
return
|
||||
}
|
||||
Ok(client)
|
||||
}
|
||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -1,8 +1,6 @@
|
|||
use eframe::egui;
|
||||
use image::GenericImageView;
|
||||
use serenity::prelude::*;
|
||||
use std::{error::Error, sync::Arc, thread, time, future::Future};
|
||||
|
||||
use std::{error::Error, sync::Arc, thread, time};
|
||||
mod bot;
|
||||
|
||||
const MAX_FPS: f32 = 30.0;
|
||||
|
@ -26,16 +24,16 @@ fn main() -> Result<(), eframe::Error> {
|
|||
|
||||
struct Jiji {
|
||||
next_frame: time::Instant,
|
||||
bot: Option<Client>,
|
||||
bot_future: Option<Box<dyn Future<Output = Result<Client, String>>>>,
|
||||
bot: thread::JoinHandle<()>,
|
||||
}
|
||||
|
||||
impl Default for Jiji {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
next_frame: time::Instant::now(),
|
||||
bot: None,
|
||||
bot_future: Some(Box::new(bot::start_discord_bot())),
|
||||
bot: thread::spawn(|| {
|
||||
bot::start_discord_bot();
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue