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.
Solution 1:
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 => {