awaitMessages()不响应discord上的任何消息



此代码是一个响应斜杠命令(/quiz(并从qiuz.json发送问题,然后等待某人发送答案并将其与quiz.json的答案进行比较的示例。机器人会发送一个问题,但根本不会记录我在频道中发送的任何消息,即使它们是正确的答案,即使我删除了过滤器。我还尝试使用createMessageCollector((,但也出现了同样的问题。

我的bot有bot、messages.read、applications.commands和guilds.members.read作用域。我还启用了这些特权网关意图、消息内容意图、服务器成员意图和存在意图。

这是我遇到问题的代码。

const quiz = require('./quiz.json');
const { SlashCommandBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('quiz')
.setDescription('quiz time!'),
async execute(interaction) {
const item = quiz[Math.floor(Math.random() * quiz.length)];
const filter = response => {
return item.answers.some(answer => answer.toLowerCase() === response.content.toLowerCase());
};
interaction.reply({ content: item.question, fetchReply: true })
.then(() => {
interaction.channel.awaitMessages({ filter, max: 1, time: 30000, errors: ['time'] })
.then(collected => {
interaction.followUp(`${collected.first().author} got the correct answer!`);
})
.catch(collected => {
interaction.followUp('Looks like nobody got the answer this time.');
});
});
},
};

我在index.js中使用了一个类似于discord.js指南中提到的命令处理程序,它似乎工作得很好。我使用的是discord.js v14.1.2和node.js v16.15.1

我发现了,问题出在我的意图和党派上,我没有阅读聊天中发送的消息所需的正确信息。我使用了一个包括所有GatewayIntentBits和Partials的模板进行测试,机器人正在工作。(我还通过我的机器人的discord开发者门户启用了它们(。

最新更新