Tyler2P
Tyler2P

Reputation: 2370

message event listener not working properly

I currently have the following code:

const Discord = require('discord.js');
const client = new Discord.Client({
    partials: ['MESSAGE', 'CHANNEL', 'REACTION']
});
const db = require('quick.db')

client.on('message', async message => {
    const DmLogger = require('./MainServer/dmRecieving.js');
    DmLogger(client, message, Discord);
    const levels = require('./MainServer/levels/main.js');
    levels(client, message)


    if (message.channel.id === configFile.LoggingChannel) return;
    if (message.author.bot) return;
    if (!message.guild) return;
    let prefix = db.get(message.guild.id + '.prefix') || '~'
    if (!message.content.startsWith(prefix)) return;
    let args = message.content
      .slice(prefix.length)
      .trim()
      .split(/ +/g);
    if (message.content.toLowerCase() == prefix + 'info') {
      const commandFile = require(`./Embeds/info.js`);
      return commandFile(client, message);
    }
    if (message.content.toLowerCase() == prefix + 'help') {
      const commandFile = require(`./Embeds/help.js`);
      return commandFile(client, prefix, message);
    }
    if (message.content.toLowerCase() == prefix + 'fonts') {
      const commandFile = require(`./Commands/font.js`);
      return commandFile(client, msg, args, prefix, message);
    }
    if (message.content.toLowerCase().startsWith(prefix + 'setup')) {
      const commandFile = require(`./Commands/setup/main.js`);
      return commandFile(client, message, db);
    }
  });

Whenever I send a message that includes a command the event listener is firing however it is not detecting the message content.
This module has been working fine for the passed few months its just suddenly erroring after I reinstalled the discord.js module.

Upvotes: 2

Views: 4630

Answers (2)

waki285
waki285

Reputation: 514

In discord.js v13, it is necessary to specify an intent in new discord.Client(). Events other than the specified intent will not be received.
ClientOptions
Intents#FLAGS

To receive the message event, you will need the GUILDS and GUILD_MESSAGES intents.

You mean...

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

Or to receive all (including privileged intent) events...

const client = new Discord.Client({
    partials: ['MESSAGE', 'CHANNEL', 'REACTION'],
    intents: Object.keys(Discord.Intents.FLAGS)
});

Also, in discord.js v13, the message event has been deprecated, so it is recommended to replace it with messageCreate.

- client.on('message', async message => {
+ client.on('messageCreate', async message => {

Upvotes: 2

RockRom
RockRom

Reputation: 63

Since discord.js v13, you need to declare what your bot is doing with Intents

Here's how you declare them :

const client = new Discord.Client({ 
   partials: ['MESSAGE', 'CHANNEL', 'REACTION'], 
   intents: ['GUILD_MESSAGES']        
})

The GUILD_MESSAGES Intent is essential because it allows your bot to read and reply to messages in guilds. However, you should check the documentation to see if your bot needs some more Intents

Upvotes: 0

Related Questions