My discord bot was working fine before, but it kept giving this error and telling me on discord that the application did not respond whenever I try to use an application command.
When I changed rest.put(Routes.applicationGuildCommands(clientId, guildId) to rest.put(Routes.applicationCommands(clientId) so the slash commands would be global instead of guild, it just stopped working and keeps giving me this error message:
TypeError: Cannot read properties of undefined (reading 'reduce')
at new BaseInteraction (My Botnode_modulesdiscord.jssrcstructuresBaseInteraction.js:106:43)
at new CommandInteraction (My Botnode_modulesdiscord.jssrcstructuresCommandInteraction.js:16:5)
at new ChatInputCommandInteraction (My Botnode_modulesdiscord.jssrcstructuresChatInputCommandInteraction.js:13:5)
at InteractionCreateAction.handle (My Botnode_modulesdiscord.jssrcclientactionsInteractionCreate.js:90:25)
at module.exports [as INTERACTION_CREATE] (My Botnode_modulesdiscord.jssrcclientwebsockethandlersINTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (My Botnode_modulesdiscord.jssrcclientwebsocketWebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (My Botnode_modulesdiscord.jssrcclientwebsocketWebSocketManager.js:239:12)
at WebSocketManager.emit (My Botnode_modules@vladfranguasync_event_emitterdistindex.cjs:282:31)
at WebSocketShard.<anonymous> (My Botnode_modules@discordjswsdistindex.js:1190:51)
at WebSocketShard.emit (My Botnode_modules@vladfranguasync_event_emitterdistindex.cjs:282:31)"
my code is this:
handleCommands.js
const { REST } = require("@discordjs/rest"); const { Routes } = require("discord-api-types/v9"); const fs = require("fs");
module.exports = (client) => { client.handleCommands = async () => { const commandFolders = fs.readdirSync("./src/commands"); for (const folder of commandFolders) { const commandFiles = fs .readdirSync(./src/commands/${folder}) .filter((file) => file.endsWith(".js"));
const { commands, commandArray } = client;
for (const file of commandFiles) {
const command = require(`../../commands/${folder}/${file}`);
commands.set(command.data.name, command);
commandArray.push(command.data.toJSON());
}
}
const clientId = '855293348515807263';
const guildId = '1140164949516230696';
const rest = new REST({ version: '9' }).setToken(process.env.token);
try {
console.log('Started refreshing application (/) commands.');
await rest.put(Routes.applicationGuildCommands(clientId, guildId), {
body: client.commandArray,
});
console.log('Successfully reloaded application (/) commands.');
} catch (error) {
console.error(error);
}
};
};
After I got the first error, I switched applicationCommands back to applicationGuildCommands (how it was originally) but it stills gives the error.
Colin Tran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.