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 serenity::all::*;
|
||||||
use crate::commands::SlashCommand;
|
use crate::commands::SlashCommand;
|
||||||
|
use crate::events::{BotEvent, EventEntry};
|
||||||
|
|
||||||
pub async fn handle(ctx: &Context, ready: &Ready, commands: &[Box<dyn SlashCommand>]) {
|
pub struct ReadyHandler;
|
||||||
println!("TTY is now running as: '{}'\n", ready.user.name);
|
|
||||||
|
|
||||||
println!("Starting command registration:");
|
#[serenity::async_trait]
|
||||||
let cmds: Vec<CreateCommand> = commands
|
impl BotEvent for ReadyHandler {
|
||||||
.iter()
|
fn event_type(&self) -> &'static str { "ready" }
|
||||||
.map(|c| c.register())
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
|
async fn on_ready(&self, ctx: &Context, ready: &Ready, commands: &[Box<dyn SlashCommand>]) {
|
||||||
|
println!("TTY is now running as: '{}'", ready.user.name);
|
||||||
|
|
||||||
|
let cmds: Vec<CreateCommand> = commands.iter().map(|c| c.register()).collect();
|
||||||
Command::set_global_commands(&ctx.http, cmds)
|
Command::set_global_commands(&ctx.http, cmds)
|
||||||
.await
|
.await
|
||||||
.expect("❌ | Cannot register commands");
|
.expect("❌ | Cannot register commands");
|
||||||
|
|
||||||
println!("\nTTY now running with {} commands loaded", commands.len());
|
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