I’ve built a Discord bot with a /support command, but it isn’t showing up when I type it in the server.
I’ve spent hours trying to resolve this issue and I’m at a loss. I’ve changed the bot’s permissions and re-invited it numerous times. My Node.js version seems fine and I followed the instructions from the discord.js documentation.
The bot logs in correctly, yet the slash command doesn’t appear in the list of commands. Here is the code I’m working with:
const { Client, GatewayIntentBits } = require('discord.js');
const { SlashCommandBuilder } = require('@discordjs/builders');
const bot = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
});
const TOKEN = "YOUR_BOT_TOKEN";
bot.on('ready', () => {
console.log(`Bot is online as ${bot.user.tag}`);
});
const supportCmd = new SlashCommandBuilder()
.setName('support')
.setDescription('Show support options and FAQ');
bot.on('interactionCreate', async (interaction) => {
if (!interaction.isCommand() || interaction.commandName !== 'support') return;
if (interaction.channelId !== 'YOUR_CHANNEL_ID') {
await interaction.reply({ content: 'Command not allowed here.', ephemeral: true });
return;
}
const optionButtons1 = [
{
type: 2,
style: 1,
label: 'Account Issues',
custom_id: 'account-help'
},
{
type: 2,
style: 1,
label: 'Technical Problems',
custom_id: 'tech-help'
},
{
type: 2,
style: 3,
label: 'Payment Help',
custom_id: 'payment-help'
}
];
const optionButtons2 = [
{
type: 2,
style: 1,
label: 'Bug Reports',
custom_id: 'bug-help'
},
{
type: 2,
style: 2,
label: 'Close',
custom_id: 'close-help'
}
];
await interaction.reply({
content: 'Support Menu Available\nChoose a category below to get help with your issue.',
components: [
{
type: 1,
components: optionButtons1
},
{
type: 1,
components: optionButtons2
}
],
ephemeral: true
});
const buttonCollector = interaction.channel?.createMessageComponentCollector({ time: 45000 });
buttonCollector?.on('collect', async (btnClick) => {
if (btnClick.customId === 'account-help') {
await btnClick.update({ content: 'Account help selected', ephemeral: true });
} else if (btnClick.customId === 'tech-help') {
await btnClick.update({ content: 'Technical support selected', ephemeral: true });
} else if (btnClick.customId === 'close-help') {
await btnClick.update({ content: 'Closing support menu...', ephemeral: true });
buttonCollector.stop();
}
});
});
bot.login(TOKEN);
What am I missing? Do I need to register the command somewhere else?