fix: interaction_create event

This commit is contained in:
Miguel da Mota 2024-02-23 19:22:19 +01:00
parent d48de636f9
commit ba42e009f4

View file

@ -41,12 +41,12 @@ struct Handler;
impl EventHandler for Handler { impl EventHandler for Handler {
async fn interaction_create(&self, ctx: Context, interaction: Interaction) { async fn interaction_create(&self, ctx: Context, interaction: Interaction) {
if let Interaction::Command(command) = interaction { if let Interaction::Command(command) = interaction {
let content = match command.data.name.as_str() { let content = Some(match command.data.name.as_str() {
"info" => Some(commands::info::run(&ctx, &command)), "info" => commands::info::run(&ctx, &command).await,
"play" => Some(commands::play::run(&ctx, &command)), "play" => commands::play::run(&ctx, &command).await,
"stop" => Some(commands::stop::run(&ctx, &command)), "stop" => commands::stop::run(&ctx, &command).await,
_ => Some(respond_with_error(&ctx, &command)), _ => respond_with_error(&ctx, &command).await,
}; });
if let Some(embed) = content { if let Some(embed) = content {
let data = CreateInteractionResponseMessage::new().embed(embed); let data = CreateInteractionResponseMessage::new().embed(embed);
@ -72,25 +72,24 @@ impl EventHandler for Handler {
pub async fn respond_with_error(_ctx: &Context, command: &CommandInteraction) -> CreateEmbed { pub async fn respond_with_error(_ctx: &Context, command: &CommandInteraction) -> CreateEmbed {
let username = &command.user.name.as_str(); let username = &command.user.name.as_str();
let current_time = Local::now().format("%Y-%m-%d @ %H:%M:%S"); let current_time = Local::now().format("%Y-%m-%d @ %H:%M:%S");
CreateEmbed::new() CreateEmbed::new()
.author(CreateEmbedAuthor::new("Rustendo")) .author(CreateEmbedAuthor::new("Rustendo"))
.title("Command not found") .title("Command not found")
.description("Cannot find the executed command") .description("Cannot find the executed command")
.footer(CreateEmbedFooter::new(format!("> {} | {}", current_time, username))) .footer(CreateEmbedFooter::new(format!(
"> {} | {}",
current_time, username
} }
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
println!(r"__________ __ .___ println!(
\______ \__ __ _______/ |_ ____ ____ __| _/____
| _/ | | ___/\ __\_/ __ \ / \ / __ |/ _ \
| | \ | |___ \ | | \ ___/ | | | /_/ ( <_> ) | | \ | |___ \ | | \ ___/ | | | /_/ ( <_> )
|____|_ /____/____ > |__| \___ >|___| |____ |\____/ |____|_ /____/____ > |__| \___ >|___| |____ |\____/
\/ \/ \/ \/ \/ \/ \/ \/ \/ \/
"); ");
// Load config // Load config
let config = config::load().unwrap(); let config = config::load().unwrap();
// Set status // Set status
@ -111,9 +110,7 @@ async fn main() {
// //
// Shards will automatically attempt to reconnect, and will perform exponential backoff until // Shards will automatically attempt to reconnect, and will perform exponential backoff until
// it reconnects. // it reconnects.
if let Err(why) = client if let Err(why) = client.start().await {
.start()
.await {
println!("Client error: {why:?}"); println!("Client error: {why:?}");
} }
} }