feat(events/bot): adding a interaction_create file
This commit is contained in:
parent
94f2ac047b
commit
a4576acdc2
1 changed files with 24 additions and 0 deletions
24
src/events/bot/interaction_create.rs
Normal file
24
src/events/bot/interaction_create.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
use serenity::all::*;
|
||||
use crate::commands::SlashCommand;
|
||||
|
||||
pub async fn handle(
|
||||
ctx: &Context,
|
||||
interaction: &Interaction,
|
||||
commands: &[Box<dyn SlashCommand>],
|
||||
) {
|
||||
let Interaction::Command(command) = interaction else {
|
||||
return;
|
||||
};
|
||||
|
||||
let name: &str = command.data.name.as_str();
|
||||
|
||||
match commands.iter().find(|cmd| cmd.name() == name) {
|
||||
Some(cmd) => {
|
||||
if let Err(why) = cmd.run(ctx, command).await {
|
||||
eprintln!("❌ | Error on {name}: {why:?}");
|
||||
}
|
||||
}
|
||||
None => eprintln!("⚠️ | Unable to fetch: /{name}"),
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue