Skip to content

Commit 5f9489d

Browse files
jacklau1993Rapi-agent
andauthored
fix(discord): Register slash commands globally only (#804)
Register Discord slash commands only at global scope so the same commands are not also created per guild. This keeps slash commands available in DMs and prevents duplicate entries in guild command pickers. Co-authored-by: Rapi-agent <rapi-agent@users.noreply.github.com>
1 parent 0079352 commit 5f9489d

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

src/discord.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -865,20 +865,25 @@ impl EventHandler for Handler {
865865
)),
866866
];
867867

868-
// Register global commands (works in DMs + all guilds after propagation).
868+
// Register global commands only. Registering the same commands per-guild
869+
// makes Discord show duplicate slash commands in guild command pickers.
869870
if let Err(e) = Command::set_global_commands(&ctx.http, commands.clone()).await {
870871
tracing::warn!(error = %e, "failed to register global slash commands");
871872
} else {
872873
info!("registered global slash commands");
873874
}
874875

875-
// Also register per-guild for instant availability (global can take up to 1h).
876+
// One-time migration cleanup: older versions registered the same
877+
// slash commands per-guild, and Discord persists those server-side.
878+
// Keep guild command sets empty so only global commands are shown.
876879
for guild in &ready.guilds {
877880
let guild_id = guild.id;
878-
if let Err(e) = guild_id.set_commands(&ctx.http, commands.clone()).await {
879-
tracing::warn!(%guild_id, error = %e, "failed to register guild slash commands");
880-
} else {
881-
info!(%guild_id, "registered guild slash commands");
881+
if let Err(e) = guild_id.set_commands(&ctx.http, Vec::new()).await {
882+
tracing::warn!(
883+
%guild_id,
884+
error = %e,
885+
"failed to clear stale guild slash commands"
886+
);
882887
}
883888
}
884889

0 commit comments

Comments
 (0)