I keep running into this reference error when trying to run my Discord bot. I have a setup where each command is in its own separate file and I load them all in my main bot file.
You’re missing the Discord import on line 4. Since you only destructured Client and Intents from discord.js, you don’t have access to the Discord object. Two fixes: either change new Discord.Collection() to new Collection() and add Collection to your destructured imports, or just use const Discord = require('discord.js') at the top. I hit this exact same problem when I refactored my bot - super easy to miss when you switch from importing everything to just grabbing specific parts. Also, heads up that your message event handler might need to be messageCreate depending on which discord.js version you’re running.
totally get it, that error is a pain! Just remember to import Collection if you wanna use it, otherwise swap to new Map(). Both ways work, just depends on what you prefer. gl with your bot!
The problem’s on line 4 - you’re using Discord.Collection() but never imported Discord. You only destructured Client and Intents from discord.js. Just change that line to bot.commands = new Map() or add Collection to your import: const { Client, Intents, Collection } = require("discord.js") then use bot.commands = new Collection(). I’d go with Map since Collection extends Map anyway and it’s less to import. Had this exact same error when I started splitting up my bot commands - this fixes it right away.