Can someone help my crash loop?
my crash loop is non stop when im trying to make a bot what am i doing wrong?
23 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!
- ✅
Marked as resolved by OPTag suggestion for @Ranner:
RangeError [BitFieldInvalid]: Invalid bitfield flag or number: undefined
- All SCREAMING_SNAKE_CASE
enums have been changed to PascalCase
- Intents: Intents.FLAGS.GUILD_MESSAGES
-> GatewayIntentBits.GuildMessages
- Permissions: Permissions.FLAGS.SEND_MESSAGES
-> PermissionFlagsBits.SendMessages
let me just show my scripts
my package.json "name": "The-Green-Mooser",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1",
"start": "node ."
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@types/node": "^18.0.6",
"discord.js": "^14.14.1",
"express": "^4.18.2",
"node-fetch": "^3.2.6"
},
"devDependencies": {
"node": "^16.20.2"
},
"description": ""
}
and my index.js const express = require("express");
const app = express();
app.listen(3000, () => {
console.log("Project is running!");
})
app.get("/", (req, res) => {
res.send("Hello world!");
})
const Discord = require("discord.js");
const client = new Discord.Client({intents: ["GUILDS", "GUILD_MESSAGES" ]});
client.on("message", message => {
if(message.content === "ping") {
message.channel.send("pong")
}
})
client.login(process.env.token);
You're using v14 but your code is still v13, so you'd need to make some changes
like what?
This, and the event name is messageCreate now, not message
You'd also need MessageContent intent if you wanna access the message's content
If you aren't getting content, embeds or attachments of a message, make sure you have the
MessageContent
intent enabled in the Developer Portal and provide it to your client:
it is enabled
You also need to put the intent in your client constructor like so
so in index.js?
Yes, if that's where your client constructor is
heres my index.js just in case. https://sourceb.in/d7Ldu1qmDf
Alright, now make the changes I said
i did ima refresh the page so it recinizes
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent]
});
didnt copy hold on
/home/runner/The-Green-moose-bot/index.js:18
const client = new Discord.Client({intents: ["GUILDS", "GUILD_MESSAGES" ]});
^
SyntaxError: Identifier 'client' has already been declared
at internalCompileFunction (node:internal/vm:77:18)
at wrapSafe (node:internal/modules/cjs/loader:1288:20)
at Module._compile (node:internal/modules/cjs/loader:1340:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
at Module.load (node:internal/modules/cjs/loader:1207:32)
at Module._load (node:internal/modules/cjs/loader:1023:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
at node:internal/main/run_main_module:28:49
Node.js v20.10.0
there
You shouldn't just blindly copy-paste, you have 2 clients, so get rid of the one you had
there i replaced it
with new one should i try now?
Yes
IT WORKED THX
You're welcome, please mark the post as solved
got it