I have created a Discord Bot using replit and node.js, and upon testing the bot, I realized that it couldn’t see the content of a sent message in the Discord Server. My bot has admin status, and I’ve enabled all 3 settings for Privileged Gateway Intents in the Discord Developer Portal, but my JSON of the received message (from block 6) still comes out as “content: “”,” (i.e content empty). I’ve also tried to reboot the bot, and tried disable and enable the settings in the Privileged Gateway Intents but still nothing. The bot sees the message, just not its content.
Here is my code:
const express = require("express");
const app = express();
app.listen(3000, () => {
console.log("Project is running!!");
});
app.get("/", (req, res) => {
res.send("Hello World!");
});
const { Client } = require("discord.js");
const client = new Client({
intents: [32767], // This number represents all available intents
});
client.on("ready", () => {
console.log('Bot has logged in as ${client.user.tag}');
});
client.on("messageCreate", (message) => {
console.log('Received message: ${JSON.stringify(message)}');
if (message.content === "ping") {
message.reply("pong");
}
});
client.login(process.env.token);
In this case, the log prints the following:
Project is running!!
Bot has logged in as ${client.user.tag}
And if a message is sent in the server the log prints:
Received message:
{"channelId":"xxxxxxxxxxxxxx","guildId":"xxxxxxxxxxxx","id":"xxxxxxxxxxxxx","createdTimestamp":xxxxxxxxxxxxx,"type":0,"system":false,"content":"","authorId":"xxxxxxxxxxxx","pinned":false,"tts":false,"nonce":"xxxxxxxxxxxxx","embeds":[],"components":[],"attachments":[],"stickers":[],"position":null,"roleSubscriptionData":null,"resolved":null,"editedTimestamp":null,"mentions":{"everyone":false,"users":[],"roles":[],"crosspostedChannels":[],"repliedUser":null,"members":[],"channels":[]},"webhookId":null,"groupActivityApplicationId":null,"applicationId":null,"activity":null,"flags":0,"reference":null,"interaction":null,"cleanContent":""}
where the content at subject 7 is empty no matter the actual content of the sent message.
I suspect it might have to do with block 4, more precisely
intents [32767]
This line is AI generated, and said to go hand in hand with the newest patch of discord.js, but I’m not too sure since its not working. Can’t find something else online tho so I am testing my luck here.
I’ve also tried changign block 4 in my previous Javascript-code for:
const { Client, Intents } = require("discord.js");
const client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]
});
But this gives me the error message:
/home/runner/Leaguelegendernas-Maid/index.js:14
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]
TypeError: Cannot read properties of undefined (reading 'FLAGS')
at Object.<anonymous> (/home/runner/Leaguelegendernas-Maid/index.js:14:21)
at Module._compile (node:internal/modules/cjs/loader:1376:14)
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
It goes without saying, but I can’t ever trigger the “pong” response. Unless i remove the “ping” in the code for an empty string, then it works.
Anyone have a fix for this? Most of thanks!