From bab3f614f8b42545fdb0101c4e353c87e0966d47 Mon Sep 17 00:00:00 2001 From: salmonik Date: Tue, 27 Oct 2026 18:18:07 +0100 Subject: music: group playback commands under /music Graduate grajcuj/skip/queue/stop/join into the /music parent and drop the top-level names. On startup, reconcile global slash commands and delete any that are no longer registered, since Discord otherwise keeps stale commands after a rename or move. Docs updated for the new command layout and queue semantics. --- src/main.rs | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 4e308b8..8d11d76 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; use std::sync::Arc; use std::time::{Duration, Instant}; @@ -236,6 +236,43 @@ async fn main() -> Result<(), Box> { poise::builtins::register_globally(ctx, &framework.options().commands).await?; + // Discord keeps global commands that disappear from the + // registration payload. Delete leftovers from renamed or + // removed commands so the move under `/music` is visible. + let expected: HashSet = framework + .options() + .commands + .iter() + .map(|command| { + command + .context_menu_name + .clone() + .unwrap_or_else(|| command.name.clone()) + }) + .collect(); + match ctx.http.get_global_commands().await { + Ok(existing) => { + for command in existing { + if !expected.contains(&command.name) { + match ctx.http.delete_global_command(command.id).await { + Ok(()) => tracing::info!( + command = %command.name, + "removed stale global command" + ), + Err(e) => tracing::warn!( + command = %command.name, + error = %e, + "failed to remove stale global command" + ), + } + } + } + } + Err(e) => { + tracing::warn!(error = %e, "could not list global commands for cleanup") + } + } + events::handle_ready(ctx).await.map_err(|e| { tracing::error!("on_ready handler: {e}"); e -- cgit v1.2.3