Slash Command Not working
PING COMMAND
module.exports.run = async (interaction) => {
const pingEmbed = new EmbedBuilder()
.setAuthor({ name:`RebootMC`, iconURL: interaction.client.user.displayAvatarURL()})
.setColor(`#fcd200`)
.setFooter({ text: `RebootMC. All rights reserved.`, iconURL: interaction.client.user.displayAvatarURL()})
.setTimestamp();
return interaction.deferReply({ embeds: [pingEmbed], ephemeral: true });
}
module.exports.help = {
name: 'ping',
desc: 'Outputs the average of the last 5 websocket pings sent to the Discord API.',
usage: 'ping',
category: 'general'
};module.exports.run = async (interaction) => {
const pingEmbed = new EmbedBuilder()
.setAuthor({ name:`RebootMC`, iconURL: interaction.client.user.displayAvatarURL()})
.setColor(`#fcd200`)
.setFooter({ text: `RebootMC. All rights reserved.`, iconURL: interaction.client.user.displayAvatarURL()})
.setTimestamp();
return interaction.deferReply({ embeds: [pingEmbed], ephemeral: true });
}
module.exports.help = {
name: 'ping',
desc: 'Outputs the average of the last 5 websocket pings sent to the Discord API.',
usage: 'ping',
category: 'general'
};Interaction Create
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}
try {
await command.run(interaction);
} catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
} else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
}); client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}
try {
await command.run(interaction);
} catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
} else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
});Event Handler
readdir("./events/", (err, files) => {
if (err) return console.error(err);
// Filter for JavaScript files and count them
let evnFiles = files.filter(f => f.split(".").pop() === 'js');
const totalFiles = evnFiles.length; // Number of .js files
console.log(`\nLoading ${totalFiles} Event Files Now...`);
if (totalFiles === 0) return console.log('\x1b[33m ⚠ - No event files found!\x1b[0m');
// Load each event file
evnFiles.forEach((f, i) => {
const props = require(`../events/${f}`);
let eventName = f.split(".")[0];
console.log(`${i + 1}: ${f} loaded!`);
client.on(eventName, props.bind(null, client));
});
}); readdir("./events/", (err, files) => {
if (err) return console.error(err);
// Filter for JavaScript files and count them
let evnFiles = files.filter(f => f.split(".").pop() === 'js');
const totalFiles = evnFiles.length; // Number of .js files
console.log(`\nLoading ${totalFiles} Event Files Now...`);
if (totalFiles === 0) return console.log('\x1b[33m ⚠ - No event files found!\x1b[0m');
// Load each event file
evnFiles.forEach((f, i) => {
const props = require(`../events/${f}`);
let eventName = f.split(".")[0];
console.log(`${i + 1}: ${f} loaded!`);
client.on(eventName, props.bind(null, client));
});
});