slash command not appearing

made a slash command, it's not appearing when i bring the bot online,
const { Client, Intents, MessageEmbed, MessageSelectMenu } = require('discord.js');
require('dotenv').config();

const dungeons = [
{
label: 'Brackenhide Hollow',
value: 'BH'
},
{
label: 'Halls of Infusion',
value: 'HoI'
},
// Add other dungeons here
];

const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES
]
});

client.once('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
});

client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;

const command = interaction.commandName;

if (command === 'ping') {
const embed = new MessageEmbed()
.setColor('#FF0000')
.setDescription('Pong! This is a red response.');

const row = new MessageActionRow()
.addComponents(
new MessageSelectMenu()
.setCustomId('select')
.setPlaceholder('Select a dungeon')
.addOptions(dungeons.map(dungeon => ({ label: dungeon.label, value: dungeon.value })))
);

await interaction.reply({ embeds: [embed], components: [row] });
}
// ...
});

client.on('interactionCreate', async interaction => {
if (interaction.isSelectMenu()) {
if (interaction.customId === 'select') {
const selectedDungeons = interaction.values
.map(value => dungeons.find(dungeon => dungeon.value === value))
.map(dungeon => dungeon.label);

await interaction.reply(`You selected: ${selectedDungeons.join(', ')}`);
}
}
});

client.login(process.env.BOT_TOKEN);
const { Client, Intents, MessageEmbed, MessageSelectMenu } = require('discord.js');
require('dotenv').config();

const dungeons = [
{
label: 'Brackenhide Hollow',
value: 'BH'
},
{
label: 'Halls of Infusion',
value: 'HoI'
},
// Add other dungeons here
];

const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES
]
});

client.once('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
});

client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;

const command = interaction.commandName;

if (command === 'ping') {
const embed = new MessageEmbed()
.setColor('#FF0000')
.setDescription('Pong! This is a red response.');

const row = new MessageActionRow()
.addComponents(
new MessageSelectMenu()
.setCustomId('select')
.setPlaceholder('Select a dungeon')
.addOptions(dungeons.map(dungeon => ({ label: dungeon.label, value: dungeon.value })))
);

await interaction.reply({ embeds: [embed], components: [row] });
}
// ...
});

client.on('interactionCreate', async interaction => {
if (interaction.isSelectMenu()) {
if (interaction.customId === 'select') {
const selectedDungeons = interaction.values
.map(value => dungeons.find(dungeon => dungeon.value === value))
.map(dungeon => dungeon.label);

await interaction.reply(`You selected: ${selectedDungeons.join(', ')}`);
}
}
});

client.login(process.env.BOT_TOKEN);
7 Replies
d.js toolkit
d.js toolkitā€¢15mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
treble/luna
treble/lunaā€¢15mo ago
did you deploy your commands
Mocus
MocusOPā€¢15mo ago
šŸ¤¦ā€ā™‚ļø no, how do i do that
d.js docs
d.js docsā€¢15mo ago
guide Creating Your Bot: Registering slash commands read more
Mocus
MocusOPā€¢15mo ago
thanks, i registered the commands but now im getting:
const row = new MessageActionRow()
^

ReferenceError: MessageActionRow is not defined
at Client.<anonymous> (C:\Users\user\OneDrive\Desktop\DNG\bot.js:54:21)
at Client.emit (node:events:526:35)
at InteractionCreateAction.handle (C:\Users\user\node_modules\discord.js\src\client\actions\InteractionCreate.js:83:12)
at module.exports [as INTERACTION_CREATE] (C:\Users\user\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (C:\Users\user\node_modules\discord.js\src\client\websocket\WebSocketManager.js:346:31)
at WebSocketShard.onPacket (C:\Users\user\node_modules\discord.js\src\client\websocket\WebSocketShard.js:493:22)
at WebSocketShard.onMessage (C:\Users\user\node_modules\discord.js\src\client\websocket\WebSocketShard.js:327:10)
at callListener (C:\Users\user\node_modules\ws\lib\event-target.js:290:14)
at WebSocket.onMessage (C:\Users\user\node_modules\ws\lib\event-target.js:209:9)
at WebSocket.emit (node:events:514:28)
const row = new MessageActionRow()
^

ReferenceError: MessageActionRow is not defined
at Client.<anonymous> (C:\Users\user\OneDrive\Desktop\DNG\bot.js:54:21)
at Client.emit (node:events:526:35)
at InteractionCreateAction.handle (C:\Users\user\node_modules\discord.js\src\client\actions\InteractionCreate.js:83:12)
at module.exports [as INTERACTION_CREATE] (C:\Users\user\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (C:\Users\user\node_modules\discord.js\src\client\websocket\WebSocketManager.js:346:31)
at WebSocketShard.onPacket (C:\Users\user\node_modules\discord.js\src\client\websocket\WebSocketShard.js:493:22)
at WebSocketShard.onMessage (C:\Users\user\node_modules\discord.js\src\client\websocket\WebSocketShard.js:327:10)
at callListener (C:\Users\user\node_modules\ws\lib\event-target.js:290:14)
at WebSocket.onMessage (C:\Users\user\node_modules\ws\lib\event-target.js:209:9)
at WebSocket.emit (node:events:514:28)
šŸ¤¦ cheers buddy, sorry really new to this! i tried v14 but problems with the intents couldn't get my head around it!
d.js docs
d.js docsā€¢15mo ago
RangeError [BitFieldInvalid]: Invalid bitfield flag or number: undefined - All SCREAMING_SNAKE_CASE enums have been changed to PascalCase - Intents: Intents.FLAGS.GUILD_MESSAGES -> GatewayIntentBits.GuildMessages - Permissions: Permissions.FLAGS.SEND_MESSAGES -> PermissionFlagsBits.SendMessages
Mocus
MocusOPā€¢15mo ago
ok let me see if i can convert this to v14 !
Want results from more Discord servers?
Add your server