0

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!

Phil
  • 157,677
  • 23
  • 242
  • 245
Miles Acq
  • 71
  • 1
  • 9
  • _"I updated to the latest version"_... from which previous version? – Phil Oct 17 '22 at 03:25
  • @Phil I'm honestly not sure.. I wrote the bot in 2020 and used it for a few months, now I'm updating the code with new features – Miles Acq Oct 17 '22 at 03:27
  • 1
    What does your version control say? What was the previous version in your `package.json` file and / or the lock file? – Phil Oct 17 '22 at 03:28
  • @Phil Ah, sorry I should have checked there first, it says 12.5.3, will update the post – Miles Acq Oct 17 '22 at 03:31
  • 1
    you have to use `messageCreate` event instead of `message`. and make sure you have enabled message content intents on discord degelopres portal for you bot. – Pooyan Oct 17 '22 at 03:34
  • 1
    I suggest you read both the [v13 migration docs](https://discordjs.guide/additional-info/changes-in-v13.html) and [v14 migration docs](https://discordjs.guide/additional-info/changes-in-v14.html) – Phil Oct 17 '22 at 03:40
  • @Phil thank you! I got it working, I'll update the post – Miles Acq Oct 17 '22 at 04:00

2 Answers2

1

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")
...
Miles Acq
  • 71
  • 1
  • 9
  • 1
    Shouldn't you be using the `messageCreate` event? From the [v14 migration guide](https://discordjs.guide/additional-info/changes-in-v14.html#events)... _"The `message` and `interaction` events are now removed. Use `messageCreate` and `interactionCreate` instead."_ – Phil Oct 17 '22 at 04:02
  • @Phil You're right, I copied the last five lines from my previous post. I just edited. Thanks for catching that – Miles Acq Oct 17 '22 at 04:06
  • So you say you added `GatewayIntentBits.DirectMessages` and the `Partials.Channel` partial and now you receive messages? None of has them anything to do with normal messages. – Zsolt Meszaros Oct 17 '22 at 06:36
  • You will also need to add `GatewayIntentBits.MessageContent` to actually get the content of the message – Caladan Oct 17 '22 at 10:44
-1

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(' ');
Tommy
  • 1,960
  • 1
  • 19
  • 32