'node:events' Error in my Discord bot

Hello Friends, I Can’t Solve Error: Cannot find module ‘node:events’ on my Discord bot. Can you help?
Note: The enable-pnpm command did not fix the problem

Console Error;

internal/modules/cjs/loader.js:613
    throw err;
    ^
Error: Cannot find module 'node:events'
Require stack:
- /rbd/pnpm-volume/8a19f291-9eab-4f97-84a3-019a804353eb/node_modules/discord.js/src/client/BaseClient.js
- /rbd/pnpm-volume/8a19f291-9eab-4f97-84a3-019a804353eb/node_modules/discord.js/src/index.js
- /app/bot.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:610:15)
    at Function.Module._load (internal/modules/cjs/loader.js:526:27)
    at Module.require (internal/modules/cjs/loader.js:666:19)
    at require (internal/modules/cjs/helpers.js:16:16)
    at Object.<anonymous> (/rbd/pnpm-volume/8a19f291-9eab-4f97-84a3-019a804353eb/node_modules/discord.js/src/client/BaseClient.js:3:22)
    at Module._compile (internal/modules/cjs/loader.js:759:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)
    at Module.load (internal/modules/cjs/loader.js:628:32)
    at Function.Module._load (internal/modules/cjs/loader.js:555:12)
    at Module.require (internal/modules/cjs/loader.js:666:19)```

Hi there - can you confirm that you’re using the required version of Node for discord.js, Node 16.6? I believe you are not, which is why it cannot find that native module.

I Did What You Said But Now I’m Getting This Error

/rbd/pnpm-volume/8a19f291-9eab-4f97-84a3-019a804353eb/node_modules/discord.js/src/util/BitField.js:152
    throw new RangeError('BITFIELD_INVALID', bit);
    ^
RangeError [BITFIELD_INVALID]: Invalid bitfield flag or number: everyone.
    at Function.resolve (/rbd/pnpm-volume/8a19f291-9eab-4f97-84a3-019a804353eb/node_modules/discord.js/src/util/BitField.js:152:11)
    at /rbd/pnpm-volume/8a19f291-9eab-4f97-84a3-019a804353eb/node_modules/discord.js/src/util/BitField.js:147:54
    at Array.map (<anonymous>)
    at Function.resolve (/rbd/pnpm-volume/8a19f291-9eab-4f97-84a3-019a804353eb/node_modules/discord.js/src/util/BitField.js:147:40)
    at Client._validateOptions (/rbd/pnpm-volume/8a19f291-9eab-4f97-84a3-019a804353eb/node_modules/discord.js/src/client/Client.js:546:33)
    at new Client (/rbd/pnpm-volume/8a19f291-9eab-4f97-84a3-019a804353eb/node_modules/discord.js/src/client/Client.js:73:10)
at Object.<anonymous> (/app/bot.js:3:16)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32) {
  [Symbol(code)]: 'BITFIELD_INVALID'
}

I’m going to guess that you have a RangeError due to an invalid bitfield.

You can search Google or Bing for these errors and find out what causes them. We can’t see your code which makes it slightly harder for the folks here.

Since I wrote the articles from google translate, I could understand a little, but I think you asked for the error code;

const client = new Discord.Client({ intents: ["everyone"] });

Note: I searched on Google but couldn’t find any results related to my mistake or (I’m new to this stuff)
I do not understand

Display of the error in the console;

Error Code;
Line 3

do you think it could be “MENTION_EVERYONE”?

I changed my code to “MENTION_EVERYONE” as you said but I keep getting the same error

Is there a possibility that there are errors elsewhere in the code?

I didn’t actually say it was MENTION_EVERYONE. I was pointing out that “everyone” was probably not a legitimate intent because it was not listed.

You should do one of two things in my opinion. If you understand programming then read the Discord.js docs. If you are relatively new to it then follow an example that already works until you understand the basics.

You need to understand what a string is, what a number is, etc. It isn’t fun but it is necessary. Is the array of intents supposed to be string values? The docs say “bitfield” so it isn’t likely to be string right?

intents are not the same as permissions, below are the allowed intents, which can be inputted into an array

  'GUILDS'
  'GUILD_MEMBERS'
  'GUILD_BANS'
  'GUILD_EMOJIS_AND_STICKERS'
  'GUILD_INTEGRATIONS'
  'GUILD_WEBHOOKS'
  'GUILD_INVITES'
  'GUILD_VOICE_STATES'
  'GUILD_PRESENCES'
  'GUILD_MESSAGES'
  'GUILD_MESSAGE_REACTIONS'
  'GUILD_MESSAGE_TYPING'
  'DIRECT_MESSAGES'
  'DIRECT_MESSAGE_REACTIONS'
  'DIRECT_MESSAGE_TYPING'

A nice solution is settings the Intents to the following
intents: Object.keys(Discord.Intents.FLAGS).map(x => Discord.Intents.FLAGS[x])

1 Like

It is considered a very bad idea to request intents a bot does not need. The use of something like GUILD_MESSAGE_TYPING to name one means an event will be called on your bot as messages are typed despite the average bot having no interest in it at all.

So You Are Now Saying, That Command is unnecessary in the bot Then I will delete that command.

UUPS
I think the command was necessary I got errors in many places

Can I add another command instead of everyone?, Or it seems like I can’t get out of this.

Now I Added ‘GUILD MESSAGES’ Command and I am getting this error.

Command On bot.js;

Line 3

image

I Changed the Command;

image

But I still get an error, but my bot seems active, its okay?

Error;

Since most of my commands, almost all of them start with a client, naturally I try to define the client for my bot, but I can’t.

Example Command For Client;

image

Writing a Discord bot typically won’t work if you just guess at the syntax. Have you read the documentation, watched a introductory video or followed an online example? You don’t conclude “lots of things start with client. so I’ll start mine that way”.

The real problem you are having and I mean this sincerely is that you aren’t thinking or studying anything before you start typing.

if (msg.content.toLowerCase() === 'Hi") will never, ever be true so you will never, ever see Hi Bro Welcome. These are introductory JavaScript issues and nothing to do with Discord.

So I’ll never be able to make a discord bot okay
no use keeping you busy, have a nice day sir

You will easily be able to make a discord bot if you start with simple examples that work. You get an example working and you edit that. When it breaks you discover what you did that made it break and repair it. As you get better you add new features.

If something doesn’t make sense you ask people for help. I’ve explained that the toLowerCase example cannot return true. If you were really interested you might discover why and be closer to writing that bot.

Never too busy to help but much too busy to write your entire app. :slight_smile:

The bot I made comes from a ready-made infrastructure and I watched a tutorial video, the guy showed a simple bot construction, I added something to the commands, delete chat command, etc. I got the error and when I opened the internet, I couldn’t find the source of the problem and asked for help here. Additionally google translate may have translated it wrong but I was always seeing the Hi Bro Welcome message, I’m just trying to make a “Simple” bot to have fun with my friends

Could you point us to the ready-made code and/or the tutorial? If Google translate is modifying your code you can see how that would create even more issues. We can’t see your code we see what translate felt like translating it to.

So I’ll suggest that you translate the text of your message but avoid putting your code through the translator.

If you look at your screenshot above (it shouldn’t have gone thru translation) you will see you are setting the content to “lowercase” and comparing it to “Hi” which clearly has a capital letter. This means they can never be equal.

You are pasting tiny snippets as well so we’re stuck wondering why you used a string like “everyone” originally. If that is in the tutorial it is seemingly a mistake. My feeling is if you copy some ready-made code from a tutorial it should work. If it doesn’t I tend to contact the author of the tutorial as they ought to know what they meant when they used a string where a bitfield is required.

You can see nobody is not interested in helping you don’t supply enough information and seemingly get a little annoyed when we don’t just fix it. Who is the original author of that code? Perhaps there are fixes posted.

I got this Infrastructure from a video on Youtube. Video;

The link where I got the code;

And I think there was a misunderstanding again, I’m not translating my code and in the videos I’ve watched people have said that the ToLowercase Command is used to detect all kinds of messages;
Hi hi hİ , as

And I’m a Turk

So there are a couple of things that are affecting your progress. I’m not going to outline them all but let’s start with you are using Discord.Js version 12.5.1. This one is old, I don’t know if it is still supported (maybe) but version 13 is the one to use going forward.

The line you originally posted looks as follows in the code you reference which doesn’t look like the original line that you posted.

const client = new Discord.Client({ disableMentions: ‘everyone’ });

Whomever said the toLowerCase function detects things was mistaken. It isn’t used for detecting things. My advice is to get your information from a “definitive source” not just some random people who may not really understand.

https://www.w3schools.com/jsref/jsref_tolowercase.asp

I realize that these sites are in English perhaps there are alternative Turkish versions but there is a Try It Yourself option so you can test things. If you test your code you will see that it will never match.

Thank you for giving me this information, I will do more research on this, I guess I should start with JavaScript first. Do you have a Training Video you recommend?

Note: I was able to return late because I have school

Note 2: I translated the site into Turkish and had the opportunity to review it.

JavaScript is the foundation so you should be familiar with it. Discord bots use a system called Node which is server-side JavaScript and typically a library named Discord.JS. Each layer is built upon the previous one so jumping into discord bots before knowing JS basics is going to be tough.

I found this, it looks like a translation of a modern JS book.

You don’t have to memorize everything, I often don’t remember the syntax for a library function I rarely use BUT I know the library has such a function so I look it up. You need to know what a variable is and a constant. Data types, assignments, comparisons, loops, etc.

If you see an example on a website and it shows things[0] you should be able to say “oh that’s an array”. If you wanted to learn chess (for instance) you should learn how the chessmen move before trying to play the game.

Thanks I’ll take a look at this

but i have a question, i was looking at the site right now, should i download it or check it on the site?

Writing code is error prone. You will probably make mistakes during this process. Pardon! You will definitely make mistakes

I Love This Word :smiley:

If you want to read it offline you can clone the project. It is a “project” but I assume mostly a translation of the book so reading it online is fine as well. I’d read it online so you don’t have to worry to much about updates.

"The only way to learn a new programming language is by writing programs in it." - Dennis Ritchie

"Testing leads to failure, and failure leads to understanding." - Burt Rutan

I just realized something, how did we get here from the reason I opened this topic? I was researching the latest node:Events error and suddenly I started reading articles about Javascript :smiley:

I also liked the articles you wrote.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.