English 中文(简体)
ReferenceError: Discord is not defined; in discord bot coding for 2023
原标题:

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

(https://www.youtube.com/watch?v=8V7iTweKKM8)

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.

问题回答

You imported the Client as destructured member from discord.js, so when you want to use it, you can do it directly;

const {Client, GatewayIntentBits, EmbedBuilder, PermissionsBitField, Permissions} = require( discord.js );
const client = new Client();

If you want your code to work; you should import the whole discord.js library as Discord;

const Discord = require( discord.js );
const client = new Discord.Client();

For the error message you are receiving

TypeError [ClientMissingIntents]: Valid intents must be provided for the Client

It means that you need a valid Intents to be able to Create a new client instance. For example:

// Create a new client instance
const client = new Client({ intents: [GatewayIntentBits.Guilds] });

Check out these docs: https://discordjs.guide/creating-your-bot/main-file.html#running-your-application

For the list of intents:





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签