#Cannot read properties of undefined (reading 'get')

8 messages · Page 1 of 1 (latest)

daring sinew
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

austere pine
#

[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);
}
},
};

grand goblet
#

You don’t define client.commands anywhere

austere pine
#

Thanks!

smoky trellisBOT
grand goblet
#

This one is the correct one