-
Hello, I am getting an error: client.commands = new Collection();
^
TypeError: Cannot set properties of undefined (setting 'commands')
at Object.<anonymous> (C:\Users\David\OneDrive\Documents\Code\JavaScript\Discord Js\HomeworkHelperBot\index.js:10:17)
at Module._compile (node:internal/modules/cjs/loader:1246:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1300:10)
at Module.load (node:internal/modules/cjs/loader:1103:32)
at Module._load (node:internal/modules/cjs/loader:942:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
at node:internal/main/run_main_module:23:47 Here is my code, the line I'm having trouble with says ERROR LINE next to it: const { token } = require("./config.json");
const { Client, Events, Collection, GatewayIntentBits } = require("discord.js");
const fs = require("node:fs");
const path = require("node:path");
const { client } = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates],
});
client.commands = new Collection(); /*<<< ERROR LINE
const commandsPath = path.join(__dirname, "commands");
const eventsPath = path.join(__dirname, "events");
const commandFiles = fs
.readdirSync(commandsPath)
.filter((file) => file.endsWith(".js"));
const eventFiles = fs
.readdirSync(eventsPath)
.filter((file) => file.endsWith(".js"));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ("data" in command && "execute" in command) {
client.commands.set(command.data.name, command);
} else {
console.log(
`[ERROR] The command at ${filePath} is missing a required "data" or "execute" property.`
);
}
}
for (const file of eventFiles) {
const filePath = path.join(eventsPath, file);
const event = require("filePath");
if (event.on) {
client.on(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
}
client.token(token); This line has worked in the past. Help would be greatly appreciated! |
Beta Was this translation helpful? Give feedback.
Answered by
monbrey
Feb 10, 2023
Replies: 1 comment 1 reply
-
const { client } = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates],
}); You're attempting to destructure a |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
almostSouji
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You're attempting to destructure a
client
property from a Client. This is undefined.