Home > Blockchain >  Why can't my discord.js bot receive messages? Updated from v12 to v14
Why can't my discord.js bot receive messages? Updated from v12 to v14

Time:10-17

I'm trying to write a bot using discord.js. Everything was working until I updated to the latest version (14.6.0) from 12.5.3 and now my bot can't seem to receive messages. I'm thinking it has something to do with the intents that Discord has implemented but I'm not exactly sure.

I'm not sure if this is relevant but I'm running nodejs version 18.11.0

Here's the relevant part of my code

const { Discord, EmbedBuilder, Client, GatewayIntentBits, Intents, IntentsBitField } = require('discord.js');
const client = new Client({ intents: [IntentsBitField.Flags.Guilds,IntentsBitField.Flags.GuildMessages] });
client.login('TOKEN');

client.on('message', msg => {
   console.log("RECIEVED MESSAGE")
...

I can get the bot to log in, but the message never logs to the console.

Thanks in advance!

CodePudding user response:

I read the migration docs as suggested by Phil, and here's the solution

for those who run into this problem in the future, here was my solution

const { Discord, EmbedBuilder, Client, GatewayIntentBits, Partials } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.DirectMessages ], partials: [Partials.Channel] });
client.login('TOKEN');

client.on('messageCreate', msg => {
   console.log("RECIEVED MESSAGE")
...

CodePudding user response:

I am using these options, you may have a try

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

    client.on('messageCreate', message => {
var args = message.content.split(' ');
  • Related