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,6 +11,9 @@ async fn on_ready(
) -> Result<(), Error> {
println!("Connected to API as {}", ready.user.name);
let register_commands = std::env::var("REGISTER_CMDS").unwrap_or_else(|_| String::from("true")).parse::<bool>().unwrap_or(true);
if register_commands {
let builder = poise::builtins::create_application_commands(&framework.options().commands);
let commands = serenity::Command::set_global_application_commands(&ctx.http, |commands| {
*commands = builder.clone();
@ -25,6 +28,7 @@ async fn on_ready(
},
Err(why) => println!("Error registering commands: {:?}", why)
}
}
Ok(())
}