p4bl0t/src/discord/mod.rs

45 lines
1.2 KiB
Rust
Raw Normal View History

2023-11-22 20:38:21 +00:00
mod commands;
pub mod error;
2023-11-22 20:38:21 +00:00
mod events;
pub mod utils;
use poise::serenity_prelude::ClientBuilder;
2023-11-22 20:38:21 +00:00
use utils::serenity;
use commands::logging;
2023-11-22 20:38:21 +00:00
use utils::{BotData, Context, Error};
use self::events::event_handler;
pub type Result = ::std::result::Result<(), Error>;
/// Bootstraps the Discord bot.
///
/// # Panics
///
/// Panics if the environment `DISCORD_TOKEN` is unavailable.
pub fn make_bot() -> ClientBuilder {
let intents = serenity::GatewayIntents::non_privileged();
let token = std::env::var("DISCORD_TOKEN").expect("missing DISCORD_TOKEN");
let framework = poise::Framework::builder()
2023-11-22 20:38:21 +00:00
.options(poise::FrameworkOptions {
commands: vec![logging()],
event_handler: |ctx, event, framework, data| {
Box::pin(event_handler(ctx, event, framework, data))
},
2023-11-22 20:38:21 +00:00
..Default::default()
})
.setup(|ctx, _ready, framework| {
Box::pin(async move {
poise::builtins::register_globally(
ctx,
&framework.options().commands,
)
.await?;
Ok(BotData::new().await?)
})
})
.build();
ClientBuilder::new(token, intents).framework(framework)
2023-11-22 20:38:21 +00:00
}