feat: start of slash commands
This commit is contained in:
parent
92ebe3b931
commit
f405cbbb93
3 changed files with 94 additions and 1 deletions
36
src/main.rs
36
src/main.rs
|
@ -1,13 +1,17 @@
|
|||
mod commands;
|
||||
|
||||
use serenity::{
|
||||
async_trait,
|
||||
client::{Context, EventHandler},
|
||||
model::{
|
||||
gateway::{GatewayIntents, Ready},
|
||||
guild,
|
||||
application::{interaction::{Interaction, InteractionResponseType}, command::Command},
|
||||
},
|
||||
Client,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
use serenity::model::prelude::interaction;
|
||||
|
||||
use skynet_discord_bot::{db_init, get_config, get_server_config, get_server_member, Config, DataBase};
|
||||
use tokio::sync::RwLock;
|
||||
|
@ -49,8 +53,38 @@ impl EventHandler for Handler {
|
|||
}
|
||||
}
|
||||
|
||||
async fn ready(&self, _ctx: Context, ready: Ready) {
|
||||
async fn ready(&self, ctx: Context, ready: Ready) {
|
||||
println!("[Main] {} is connected!", ready.user.name);
|
||||
|
||||
|
||||
Command::set_global_application_commands(&ctx.http, |commands| {
|
||||
commands
|
||||
.create_application_command(|command| commands::link_email::register(command))
|
||||
})
|
||||
.await.ok();
|
||||
|
||||
}
|
||||
|
||||
async fn interaction_create(&self, ctx: Context, interaction: Interaction) {
|
||||
if let Interaction::ApplicationCommand(command) = interaction {
|
||||
//println!("Received command interaction: {:#?}", command);
|
||||
|
||||
let content = match command.data.name.as_str() {
|
||||
"link" => commands::link_email::run(&command, &ctx).await,
|
||||
_ => "not implemented :(".to_string(),
|
||||
};
|
||||
|
||||
if let Err(why) = command
|
||||
.create_interaction_response(&ctx.http, |response| {
|
||||
response
|
||||
.kind(InteractionResponseType::ChannelMessageWithSource)
|
||||
.interaction_response_data(|message| message.content(content).ephemeral(true))
|
||||
})
|
||||
.await
|
||||
{
|
||||
println!("Cannot respond to slash command: {}", why);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue