client.commands = new Discord.Collection();
^
ReferenceError: Discord is not defined
at Object.<anonymous> (C:\Users\name\OneDrive\Desktop\VSC
Project 1\main.js:10:23)
←[90m at Module._compile (node:internal/modules/cjs/loader:1101:14)←[39m
←[90m at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)←[39m
←[90m at Module.load (node:internal/modules/cjs/loader:981:32)←[39m
←[90m at Function.Module._load (node:internal/modules/cjs/loader:822:12)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)←[39m
←[90m at node:internal/main/run_main_module:17:47←[39m
const { Client, Intents, DiscordAPIError } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
// Lines 1 & 2 were changed from original tutorial in order to fix the Intents not defined error
const prefix = '-';
const fs = require('fs');
client.commands = new Discord.Collection(); // * Error is thrown here *
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
I can share any of the other code if it's needed. Any help appreciated, since I don't know what's wrong :)
This was caused as you have not required your package discord.js
as to a single constant Discord
, you see every package is a module which has various properties and functions as displayed below:
const { Client, Intents, DiscordAPIError, Collection } = require('discord.js');
// then you may define it like so
client.commands = new Collection()
This would be absolutely valid as you can see here: