Refactor command registration logic

This commit is contained in:
toast 2023-12-05 14:25:20 +11:00
parent d33a479f5c
commit 29aa5e2463

View File

@ -11,19 +11,23 @@ async fn on_ready(
) -> Result<(), Error> { ) -> Result<(), Error> {
println!("Connected to API as {}", ready.user.name); println!("Connected to API as {}", ready.user.name);
let builder = poise::builtins::create_application_commands(&framework.options().commands); let register_commands = std::env::var("REGISTER_CMDS").unwrap_or_else(|_| String::from("true")).parse::<bool>().unwrap_or(true);
let commands = serenity::Command::set_global_application_commands(&ctx.http, |commands| {
*commands = builder.clone();
commands
}).await;
match commands { if register_commands {
Ok(cmdmap) => { let builder = poise::builtins::create_application_commands(&framework.options().commands);
for command in cmdmap.iter() { let commands = serenity::Command::set_global_application_commands(&ctx.http, |commands| {
println!("Registered command globally: {}", command.name); *commands = builder.clone();
} commands
}, }).await;
Err(why) => println!("Error registering commands: {:?}", why)
match commands {
Ok(cmdmap) => {
for command in cmdmap.iter() {
println!("Registered command globally: {}", command.name);
}
},
Err(why) => println!("Error registering commands: {:?}", why)
}
} }
Ok(()) Ok(())