Mentioning slash commands not working
Hi, i want to mention the slash command so that its clickable.
I think i did the code right can you help
I think i did the code right can you help
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const fs = require('fs');
const path = require('path');
module.exports = {
data: new SlashCommandBuilder()
.setName('help')
.setDescription('Show help menu'),
async execute(interaction) {
try {
const commandsPath = path.join(__dirname, '..', 'Utility');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
const commandMentions = [];
for (const file of commandFiles) {
const command = require(path.join(commandsPath, file));
const commandData = command.data;
// Fetch command ID
const commands = await interaction.client.application.commands.fetch();
const cmd = commands.find(c => c.name === commandData.name);
if (cmd) {
commandMentions.push(`<@&${cmd.id}>: ${commandData.description}`);
}
else {
commandMentions.push(`/${commandData.name}: ${commandData.description}`);
}
}
const embed = new EmbedBuilder()
.setColor('#000001')
.setTitle('Available Commands')
.setDescription(commandMentions.join('\n'));
await interaction.reply({ embeds: [embed], ephemeral: true });
}
catch (error) {
console.error(error);
await interaction.reply({ content: 'There was an error while fetching commands.', ephemeral: true });
}
},
};const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const fs = require('fs');
const path = require('path');
module.exports = {
data: new SlashCommandBuilder()
.setName('help')
.setDescription('Show help menu'),
async execute(interaction) {
try {
const commandsPath = path.join(__dirname, '..', 'Utility');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
const commandMentions = [];
for (const file of commandFiles) {
const command = require(path.join(commandsPath, file));
const commandData = command.data;
// Fetch command ID
const commands = await interaction.client.application.commands.fetch();
const cmd = commands.find(c => c.name === commandData.name);
if (cmd) {
commandMentions.push(`<@&${cmd.id}>: ${commandData.description}`);
}
else {
commandMentions.push(`/${commandData.name}: ${commandData.description}`);
}
}
const embed = new EmbedBuilder()
.setColor('#000001')
.setTitle('Available Commands')
.setDescription(commandMentions.join('\n'));
await interaction.reply({ embeds: [embed], ephemeral: true });
}
catch (error) {
console.error(error);
await interaction.reply({ content: 'There was an error while fetching commands.', ephemeral: true });
}
},
};