ReferenceError: Discord is not defined
at Object.<anonymous> (/home/runner/testing-a-bot/index.js:2:16)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
I was attempting to create a discord bot, this error has popped up.
All of the code was in the below youtube video
My code for this:
const {Client, GatewayIntentBits, EmbedBuilder, PermissionsBitField, Permissions} = require('discord.js');
const client = new Discord.Client();
client.on("ready", () => {
console.log("It's ready")
})
client.login(assume the token is here)
I ran the code, this popped up.
Just attempting to get the bot online and run basic code.
This problem isn’t a duplicate, as far as I can tell the old posts don’t work due to the age.
2
Answers
You imported the Client as destructured member from discord.js, so when you want to use it, you can do it directly;
If you want your code to work; you should import the whole discord.js library as
Discord
;Follow-up
Discord bots need intents, you need to declare them when initializing a new client;
You can check this out in the official documentation.
For the error message you are receiving
It means that you need a valid Intents to be able to Create a new client instance. For example:
Check out these docs:
https://discordjs.guide/creating-your-bot/main-file.html#running-your-application
For the list of intents: