aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main.rs39
1 files changed, 38 insertions, 1 deletions
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 @@
1use std::collections::HashMap; 1use std::collections::{HashMap, HashSet};
2use std::sync::Arc; 2use std::sync::Arc;
3use std::time::{Duration, Instant}; 3use std::time::{Duration, Instant};
4 4
@@ -236,6 +236,43 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
236 236
237 poise::builtins::register_globally(ctx, &framework.options().commands).await?; 237 poise::builtins::register_globally(ctx, &framework.options().commands).await?;
238 238
239 // Discord keeps global commands that disappear from the
240 // registration payload. Delete leftovers from renamed or
241 // removed commands so the move under `/music` is visible.
242 let expected: HashSet<String> = framework
243 .options()
244 .commands
245 .iter()
246 .map(|command| {
247 command
248 .context_menu_name
249 .clone()
250 .unwrap_or_else(|| command.name.clone())
251 })
252 .collect();
253 match ctx.http.get_global_commands().await {
254 Ok(existing) => {
255 for command in existing {
256 if !expected.contains(&command.name) {
257 match ctx.http.delete_global_command(command.id).await {
258 Ok(()) => tracing::info!(
259 command = %command.name,
260 "removed stale global command"
261 ),
262 Err(e) => tracing::warn!(
263 command = %command.name,
264 error = %e,
265 "failed to remove stale global command"
266 ),
267 }
268 }
269 }
270 }
271 Err(e) => {
272 tracing::warn!(error = %e, "could not list global commands for cleanup")
273 }
274 }
275
239 events::handle_ready(ctx).await.map_err(|e| { 276 events::handle_ready(ctx).await.map_err(|e| {
240 tracing::error!("on_ready handler: {e}"); 277 tracing::error!("on_ready handler: {e}");
241 e 278 e