feat(events/ready): adding the Interaction handle autodetect
This commit is contained in:
parent
4a832f75be
commit
cd85236218
1 changed files with 18 additions and 11 deletions
|
|
@ -1,18 +1,25 @@
|
|||
use serenity::all::*;
|
||||
use crate::commands::SlashCommand;
|
||||
use crate::events::{BotEvent, EventEntry};
|
||||
|
||||
pub async fn handle(ctx: &Context, ready: &Ready, commands: &[Box<dyn SlashCommand>]) {
|
||||
println!("TTY is now running as: '{}'\n", ready.user.name);
|
||||
pub struct ReadyHandler;
|
||||
|
||||
println!("Starting command registration:");
|
||||
let cmds: Vec<CreateCommand> = commands
|
||||
.iter()
|
||||
.map(|c| c.register())
|
||||
.collect();
|
||||
#[serenity::async_trait]
|
||||
impl BotEvent for ReadyHandler {
|
||||
fn event_type(&self) -> &'static str { "ready" }
|
||||
|
||||
Command::set_global_commands(&ctx.http, cmds)
|
||||
.await
|
||||
.expect("❌ | Cannot register commands");
|
||||
async fn on_ready(&self, ctx: &Context, ready: &Ready, commands: &[Box<dyn SlashCommand>]) {
|
||||
println!("TTY is now running as: '{}'", ready.user.name);
|
||||
|
||||
println!("\nTTY now running with {} commands loaded", commands.len());
|
||||
let cmds: Vec<CreateCommand> = commands.iter().map(|c| c.register()).collect();
|
||||
Command::set_global_commands(&ctx.http, cmds)
|
||||
.await
|
||||
.expect("❌ | Cannot register commands");
|
||||
|
||||
println!("TTY now running with {} commands loaded", commands.len());
|
||||
}
|
||||
}
|
||||
|
||||
inventory::submit! {
|
||||
EventEntry { create: || Box::new(ReadyHandler) }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue