I’m working on a Discord bot and having trouble getting my slash commands to register properly. The /support
command I created doesn’t show up when I type it in my server.
I’ve already tried adjusting bot permissions and reinviting it multiple times but nothing seems to work. My Node.js version should be fine. Here’s my current code:
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 supportCommand = 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 available here.', ephemeral: true });
return;
}
const menuButtons = [
{
type: 2,
style: 1,
label: 'Account Issues',
custom_id: 'account-btn'
},
{
type: 2,
style: 1,
label: 'Technical Support',
custom_id: 'tech-btn'
},
{
type: 2,
style: 2,
label: 'Close',
custom_id: 'close-btn'
}
];
await interaction.reply({
content: 'Support menu loaded. Choose your issue type:',
components: [{
type: 1,
components: menuButtons
}],
ephemeral: true
});
const buttonCollector = interaction.channel?.createMessageComponentCollector({ time: 30000 });
buttonCollector?.on('collect', async (btnClick) => {
if (btnClick.customId === 'account-btn') {
await btnClick.update({ content: 'Account help selected' });
} else if (btnClick.customId === 'tech-btn') {
await btnClick.update({ content: 'Technical support selected' });
} else if (btnClick.customId === 'close-btn') {
await btnClick.update({ content: 'Menu closed' });
buttonCollector.stop();
}
});
});
bot.login(TOKEN);
What am I missing to make the slash command visible in Discord?