消息事件侦听器无法正常工作 [英] message event listener not working properly
问题描述
我目前有以下代码:
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);
}
});
每当我发送包含命令的消息时,事件侦听器都会触发,但它不会检测到消息内容.
这个模块在过去的几个月里一直运行良好,只是在我重新安装 discord.js
模块后突然出错.
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.
推荐答案
在 discord.js v13 中,需要在 new discord.Client()
中指定意图.不接收指定意图以外的事件.
ClientOptions
Intents#FLAGS
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
要接收 message
事件,您需要 GUILDS
和 GUILD_MESSAGES
意图.
To receive the message
event, you will need the GUILDS
and GUILD_MESSAGES
intents.
你是说……
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)
});
另外,在 discord.js v13 中,message
事件已被弃用,因此建议将其替换为 messageCreate
.
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 => {
这篇关于消息事件侦听器无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!