I’m experiencing issues with my Discord bot not updating its commands
For some reason, my bot is only showing older commands that I thought I deleted, along with a couple of commands that aren’t in my code anymore. The new commands I recently added just won’t show up at all.
Here’s what I’ve done so far:
- Removed the bot from my server and re-invited it
- Turned off slash commands for a whole day and then turned them back on
- Tried adding a temporary command to see if it would refresh the list
This is how my command handler is set up:
package com.example.handlers;
import lombok.RequiredArgsConstructor;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
@RequiredArgsConstructor
@Component
public class SlashHandler extends ListenerAdapter {
private final PlayMusic playMusic;
private final StopMusic stopMusic;
private final ShowPlaylist showPlaylist;
private final ConnectVoice connectVoice;
private final ConfigChannel configChannel;
private final ListCards listCards;
private final AddCard addCard;
private final RemoveCard removeCard;
private final GenerateLink generateLink;
@Override
public void onSlashCommandInteraction(SlashCommandInteractionEvent event) {
String cmd = event.getName();
try {
switch (BotCommands.valueOf(cmd)) {
case playmusic:
playMusic.run(event);
break;
case stopmusic:
stopMusic.run(event);
break;
case showplaylist:
showPlaylist.run(event);
break;
case connectvoice:
connectVoice.run(event);
break;
case configchannel:
configChannel.run(event);
break;
case listcards:
listCards.run(event);
break;
case addcard:
addCard.run(event);
break;
case removecard:
removeCard.run(event);
break;
case generatelink:
generateLink.run(event);
break;
}
} catch (Exception ex) {
System.out.println("Error running command: " + ex.getMessage());
}
}
}
Command Setup:
package com.example.handlers;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
@Component
public class CommandBuilder {
public List<CommandData> commands = new ArrayList<>();
public CommandBuilder(PlayMusic playMusic, StopMusic stopMusic, ShowPlaylist showPlaylist, ConnectVoice connectVoice, ConfigChannel configChannel, ListCards listCards, AddCard addCard, RemoveCard removeCard, GenerateLink generateLink) {
commands.add(Commands.slash(playMusic.getName(), playMusic.getDesc()).addOptions(playMusic.getOptions()));
commands.add(Commands.slash(stopMusic.getName(), stopMusic.getDesc()));
commands.add(Commands.slash(showPlaylist.getName(), showPlaylist.getDesc()));
commands.add(Commands.slash(connectVoice.getName(), connectVoice.getDesc()));
commands.add(Commands.slash(configChannel.getName(), configChannel.getDesc()));
commands.add(Commands.slash(listCards.getName(), listCards.getDesc()));
commands.add(Commands.slash(addCard.getName(), addCard.getDesc()).addOptions(addCard.getOptions()));
commands.add(Commands.slash(removeCard.getName(), removeCard.getDesc()).addOptions(removeCard.getOptions()));
commands.add(Commands.slash(generateLink.getName(), generateLink.getDesc()));
}
public void register(BotCommand command) {
commands.add(Commands.slash(command.getName(), command.getDesc()).addOptions(command.getOptions()));
}
}
Anyone have any idea why this might be happening? The commands don’t seem to sync correctly with Discord.