/reload error

/reload gives an error when i try to reload a command Error while executing this command (inside discord ) Code:
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
category: 'utility',
data: new SlashCommandBuilder()
.setName('reload')
.setDescription('Reloads a command.')
.addStringOption(option =>
option.setName('command')
.setDescription('The command to reload.')
.setRequired(true)),
async execute(interaction) {
const commandName = interaction.options.getString('command', true).toLowerCase();
const command = interaction.client.commands.get(commandName);

if (!command) {
return interaction.reply(`There is no command with name \`${commandName}\`!`);
}

delete require.cache[require.resolve(`../${command.category}/${command.data.name}.js`)];

try {
interaction.client.commands.delete(command.data.name);
const newCommand = require(`../${command.category}/${command.data.name}.js`);
interaction.client.commands.set(newCommand.data.name, newCommand);
await interaction.reply(`Command \`${newCommand.data.name}\` was reloaded!`);
} catch (error) {
console.error(error);
await interaction.reply(`There was an error while reloading a command \`${command.data.name}\`:\n\`${error.message}\``);
}
},
};
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
category: 'utility',
data: new SlashCommandBuilder()
.setName('reload')
.setDescription('Reloads a command.')
.addStringOption(option =>
option.setName('command')
.setDescription('The command to reload.')
.setRequired(true)),
async execute(interaction) {
const commandName = interaction.options.getString('command', true).toLowerCase();
const command = interaction.client.commands.get(commandName);

if (!command) {
return interaction.reply(`There is no command with name \`${commandName}\`!`);
}

delete require.cache[require.resolve(`../${command.category}/${command.data.name}.js`)];

try {
interaction.client.commands.delete(command.data.name);
const newCommand = require(`../${command.category}/${command.data.name}.js`);
interaction.client.commands.set(newCommand.data.name, newCommand);
await interaction.reply(`Command \`${newCommand.data.name}\` was reloaded!`);
} catch (error) {
console.error(error);
await interaction.reply(`There was an error while reloading a command \`${command.data.name}\`:\n\`${error.message}\``);
}
},
};
6 Replies
d.js toolkit
d.js toolkit4mo 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! - Marked as resolved by OP
</JustTheDev>
</JustTheDev>4mo ago
When i run /reload in discord it gives this as reply: There was an error while executing this command! I also get this error when i run my /shard command (code:
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('shard')
.setDescription('Replies with the current shard'),
async execute(interaction) {
await interaction.reply(`Shard ${interaction.shard.id}`);
},
};
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('shard')
.setDescription('Replies with the current shard'),
async execute(interaction) {
await interaction.reply(`Shard ${interaction.shard.id}`);
},
};
chewie 🌈
chewie 🌈4mo ago
then you should log the error in your interactionCreate event and not just log that there was an error.
</JustTheDev>
</JustTheDev>4mo ago
The error i get with /shard is
TypeError: Cannot read properties of undefined (reading 'id')
at Object.execute (C:\Users\OE104655\Videos\JEMOJI DC Workspace\commands\utility\shard.js:8:54)
at Client.<anonymous> (C:\Users\OE104655\Videos\JEMOJI DC Workspace\bot.js:57:17)
at Client.emit (node:events:517:28)
at InteractionCreateAction.handle (C:\Users\OE104655\Videos\JEMOJI DC Workspace\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (C:\Users\OE104655\Videos\JEMOJI DC Workspace\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (C:\Users\OE104655\Videos\JEMOJI DC Workspace\node_modules\discord.js\src\client\websocket\WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (C:\Users\OE104655\Videos\JEMOJI DC Workspace\node_modules\discord.js\src\client\websocket\WebSocketManager.js:239:12)
at WebSocketManager.emit (C:\Users\OE104655\Videos\JEMOJI DC Workspace\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
at WebSocketShard.<anonymous> (C:\Users\OE104655\Videos\JEMOJI DC Workspace\node_modules\@discordjs\ws\dist\index.js:1173:51)
at WebSocketShard.emit (C:\Users\OE104655\Videos\JEMOJI DC Workspace\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
TypeError: Cannot read properties of undefined (reading 'id')
at Object.execute (C:\Users\OE104655\Videos\JEMOJI DC Workspace\commands\utility\shard.js:8:54)
at Client.<anonymous> (C:\Users\OE104655\Videos\JEMOJI DC Workspace\bot.js:57:17)
at Client.emit (node:events:517:28)
at InteractionCreateAction.handle (C:\Users\OE104655\Videos\JEMOJI DC Workspace\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (C:\Users\OE104655\Videos\JEMOJI DC Workspace\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (C:\Users\OE104655\Videos\JEMOJI DC Workspace\node_modules\discord.js\src\client\websocket\WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (C:\Users\OE104655\Videos\JEMOJI DC Workspace\node_modules\discord.js\src\client\websocket\WebSocketManager.js:239:12)
at WebSocketManager.emit (C:\Users\OE104655\Videos\JEMOJI DC Workspace\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
at WebSocketShard.<anonymous> (C:\Users\OE104655\Videos\JEMOJI DC Workspace\node_modules\@discordjs\ws\dist\index.js:1173:51)
at WebSocketShard.emit (C:\Users\OE104655\Videos\JEMOJI DC Workspace\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
And the error with /reload:
Error: Cannot find module '../undefined/ping.js'
Require stack:
- C:\Users\OE104655\Videos\JEMOJI DC Workspace\commands\utility\reload.js
- C:\Users\OE104655\Videos\JEMOJI DC Workspace\bot.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
at Function.resolve (node:internal/modules/cjs/helpers:125:19)
at Object.execute (C:\Users\OE104655\Videos\JEMOJI DC Workspace\commands\utility\reload.js:20:32)
at Client.<anonymous> (C:\Users\OE104655\Videos\JEMOJI DC Workspace\bot.js:57:17)
at Client.emit (node:events:517:28)
at InteractionCreateAction.handle (C:\Users\OE104655\Videos\JEMOJI DC Workspace\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (C:\Users\OE104655\Videos\JEMOJI DC Workspace\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (C:\Users\OE104655\Videos\JEMOJI DC Workspace\node_modules\discord.js\src\client\websocket\WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (C:\Users\OE104655\Videos\JEMOJI DC Workspace\node_modules\discord.js\src\client\websocket\WebSocketManager.js:239:12)
at WebSocketManager.emit (C:\Users\OE104655\Videos\JEMOJI DC Workspace\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\OE104655\\Videos\\JEMOJI DC Workspace\\commands\\utility\\reload.js',
'C:\\Users\\OE104655\\Videos\\JEMOJI DC Workspace\\bot.js'
]
}
Error: Cannot find module '../undefined/ping.js'
Require stack:
- C:\Users\OE104655\Videos\JEMOJI DC Workspace\commands\utility\reload.js
- C:\Users\OE104655\Videos\JEMOJI DC Workspace\bot.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
at Function.resolve (node:internal/modules/cjs/helpers:125:19)
at Object.execute (C:\Users\OE104655\Videos\JEMOJI DC Workspace\commands\utility\reload.js:20:32)
at Client.<anonymous> (C:\Users\OE104655\Videos\JEMOJI DC Workspace\bot.js:57:17)
at Client.emit (node:events:517:28)
at InteractionCreateAction.handle (C:\Users\OE104655\Videos\JEMOJI DC Workspace\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (C:\Users\OE104655\Videos\JEMOJI DC Workspace\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (C:\Users\OE104655\Videos\JEMOJI DC Workspace\node_modules\discord.js\src\client\websocket\WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (C:\Users\OE104655\Videos\JEMOJI DC Workspace\node_modules\discord.js\src\client\websocket\WebSocketManager.js:239:12)
at WebSocketManager.emit (C:\Users\OE104655\Videos\JEMOJI DC Workspace\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\OE104655\\Videos\\JEMOJI DC Workspace\\commands\\utility\\reload.js',
'C:\\Users\\OE104655\\Videos\\JEMOJI DC Workspace\\bot.js'
]
}
chewie 🌈
chewie 🌈4mo ago
your ping command doesn't have a category property and interaction.shard isn't a thing interaction.guild.shard.id should be correct
</JustTheDev>
</JustTheDev>4mo ago
thx!