#Cannot read properties of undefined (reading 'get')
8 messages · Page 1 of 1 (latest)
[email protected]
v16.19.0
index.js code:
const fs = require("node:fs");
const path = require("node:path");
const { Client, GatewayIntentBits } = require("discord.js");
const { token } = require("./config.json");
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
const eventsPath = path.join(__dirname, "events");
const eventFiles = fs
.readdirSync(eventsPath)
.filter((file) => file.endsWith(".js"));
for (const file of eventFiles) {
const filePath = path.join(eventsPath, file);
const event = require(filePath);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
}
client.login(token);
interactionCreate.js code:
module.exports = {
name: "interactionCreate",
async execute(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.execute(interaction);
} catch (error) {
``console.error(``Error executing ``${interaction.commandName});
console.error(error);
}
},
};
You don’t define client.commands anywhere
where should I put that?
Thanks!
This one is the correct one
Creating Your Bot: Command handling