-1

enter image description here

i am trying to create my own discord bot and it gives me that error I don't know what to do it's giving me that error

enter image description here

can you help me, please?

my version of discord.js is 14.0.3 and my node.js version is 18.5.0

I tried everything that I could even your tips and I can't do this so do you have any tips to please help me because I promised a friend I would help him

I GOTTA SAY THAT ITS THE FIRST TIME THAT IT HAPPENED TO ME AND BEFORE THAT I CREATED 2 BOTS

Adam Adam
  • 1
  • 1
  • to check your discord.js version go to package.json, and check the part where it's `"discord.js" : "v......"`, the v... is your version of discord.js. Also please put your code directly as text instead of an image. So edit your message now to include everything I just said – Staxlinou Jul 19 '22 at 23:38
  • but how can you help me with the error – Adam Adam Jul 19 '22 at 23:42
  • 1
    Does this answer your question? [Discord.js v13 code breaks when upgrading to v14](https://stackoverflow.com/questions/73028854/discord-js-v13-code-breaks-when-upgrading-to-v14) – Zsolt Meszaros Jul 20 '22 at 06:55

3 Answers3

1

In discord.js v14, Intents have been replaced by GatewayIntentBits. Therefore, the correct way for creating the client is like this:

const { Client, GatewayIntentBits } = require('discord.js')
const client = new Client({
    intents: [
        GatewayIntentBits.Guilds,
        // ...
    ]
})

For more information, you can go here => Discord.js v13 code breaks when upgrading to v14

Caladan
  • 2,261
  • 2
  • 6
  • 19
  • but now it sais "GatewayIntentBits is not defined" – Adam Adam Jul 20 '22 at 03:37
  • You haven't imported `GatewayIntentBits` from `discord.js` at the top which is why the error is coming. Add this line to the top => `const { GatewayIntentBits } = require('discord.js')` – Caladan Jul 20 '22 at 11:16
0

They changed how this works in discord.js v14. Example from the official updating guide:

const { Client, Intents } = require('discord.js'); // old
const { Client, GatewayIntentBits, Partials } = require('discord.js'); // new

const client = new Client({ intents: [Intents.FLAGS.GUILDS], partials: ['CHANNEL'] }); // old
const client = new Client({ intents: [GatewayIntentBits.Guilds], partials: [Partials.Channel] }); // new
ignis
  • 431
  • 4
  • 10
-1

This error will happen if intents are missing or not properly listed. Refer to the code here and it will work.

const Discord = require('discord.js');
const client = new.Discord.Client({
    intents: [
        "GUILDS",
         "GUILD_MESSAGES"
        ]
});
Ravioli
  • 33
  • 1
  • 6