最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Running a discord.js node keeps returning ReferenceError: Intents is not defined - Stack Overflow

programmeradmin1浏览0评论

I am an absolute beginner to making a Discord.js bot. Currently I'm trying to run a tutorial bot for the first time but I keep getting ReferenceError: Intents is not defined for the following source code.

const Discord = require('discord.js');

const client = new Discord.Client({ intents: [Discord.Intents.FLAGS.DIRECT_MESSAGES, Discord.Intents.FLAGS.GUILD_MESSAGES] });

client.once('ready', () => {
    console.log('Ready!');
});

client.login('token here');

Here's my full error log:

ReferenceError: Intents is not defined
    at Object.<anonymous> (C:\Users\duyba\source\DiscordBot\main.js:2:47)
    at Module._pile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
    at internal/main/run_main_module.js:17:47

Thank you for your attention.

I am an absolute beginner to making a Discord.js bot. Currently I'm trying to run a tutorial bot for the first time but I keep getting ReferenceError: Intents is not defined for the following source code.

const Discord = require('discord.js');

const client = new Discord.Client({ intents: [Discord.Intents.FLAGS.DIRECT_MESSAGES, Discord.Intents.FLAGS.GUILD_MESSAGES] });

client.once('ready', () => {
    console.log('Ready!');
});

client.login('token here');

Here's my full error log:

ReferenceError: Intents is not defined
    at Object.<anonymous> (C:\Users\duyba\source\DiscordBot\main.js:2:47)
    at Module._pile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
    at internal/main/run_main_module.js:17:47

Thank you for your attention.

Share Improve this question asked Aug 9, 2021 at 23:45 Bach Le DuyBach Le Duy 511 gold badge2 silver badges6 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

For anyone using discord.js v14, the method has changed. Now you need to use:

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

const client = new Client({ intents: [GatewayIntentBits.Guilds], partials: [Partials.Channel] });

Check the full v13 to v14 guide here.

The intent flags are not necesary. Simply just put them as strings like this:

const client = new Discord.Client({ intents: [ 'DIRECT_MESSAGES', 'GUILD_MESSAGES' ] });

In version 13.1.0 at this date. You must import the flags from the package.

const { Client, Intents } = require('discord.js');

As shown here

发布评论

评论列表(0)

  1. 暂无评论