I am a beginner to using discord.js and cannot figure out why my bot isn't replying with a message whenever I send one on the server it's on. Discord says it's online and "Logged in!" comes up in the console when I run it, so client.on("ready") is working, but for some reason client.on("message") isn't. I was wondering if anyone could help me troubleshoot this, I've looked up multiple tutorials and everything looks right to me despite not working. Here is my code below:
const { Client, Intents} = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const Wordle = require("./wordle.js");
client.once('ready', () => {
console.log('The bot is online');
});
client.on('messageCreate', async msg =>
{
//check for permission to post
permision = msg.channel.permissionsFor(client.user);
permision = permision.toArray();
//dont respond to own messages
if(msg.author.username === client.user.username) {return;}
//loads a new wordle game
if(msg.content.includes("!playwordle"))
{
Wordle.LoadNewWordle(msg);
}
//makes a guess in a wordle game
if(msg.content.includes("!guess"))
{
Wordle.PlayWordle(msg);
}
//shows your stats
if(msg.content.includes("!wordlestats"))
{
Wordle.ShowWordleStats(msg);
}
});
client.login('xxx');
Do you have the MESSAGE CONTENT INTENT checkbox checked in the discord developer portal?
Since August 31, 2022 access to message content became a Privileged Intent—like presence and guild member data.
If you don't have this checkbox checked you can find it in the portal https://discord.com/developers/applications > select your application > Bot > MESSAGE CONTENT INTENT
Source: https://autocode.com/discord/threads/what-are-discord-privileged-intents-and-how-do-i-enable-them-tutorial-0c3f9977/
That might solve your issue