Discord.js - 反应收集器似乎不起作用,知道为什么吗?

问题描述 投票:0回答:1

反应收集器似乎不适合我,我希望能够收集消息或嵌入的反应。

这是我创建的斜线命令

const { SlashCommandBuilder } = require('discord.js');

module.exports = {
 data: new SlashCommandBuilder()
     .setName('ping')
     .setDescription('Replies with Pong!'),
 async execute(interaction) {
     try {
         console.log(`User ${interaction.user.tag} used the /ping command.`);

         await interaction.reply('React with any emoji within 15 seconds.');

         // Get the message object
         const message = await interaction.fetchReply();

         // Reaction collector 
         const filter = (reaction, user) => user.id === interaction.user.id;
         const collector = message.createReactionCollector({ filter, time: 15000 });

         collector.on('collect', (reaction, user) => {
             console.log(`User ${user.tag} reacted with ${reaction.emoji.name}`);
         });

         collector.on('end', (collected, reason) => {
             console.log(`Collected ${collected.size} reactions. Reason: ${reason}`);
         });

                     // Log when collector starts
                     console.log('Reaction collector started.');

     } catch (error) {
         console.error(`Error: ${error.message}`);
     }
 },
};

以及我反应后在控制台中得到的结果:

User xxxx used the /ping command. Collected 0 items. Reason: time

我已在开发者网站上验证了权限: 权限有:应用程序命令、机器人、管理消息、发送消息、读取消息。 我还有许多其他斜杠命令和函数正在运行。

我已经尝试过嵌入和常规消息。我尝试倾听任何反应,因为我认为这可能是竖起大拇指的类型。

不确定接下来要测试什么,或者我是否遗漏了一些明显的东西

查看不和谐指南,这应该有效:

https://discordjs.guide/popular-topics/collectors.html#await-reactions

discord.js
1个回答
0
投票

你的问题是这里的这段代码:

const collector = interaction.channel.createMessageComponentCollector({
   filter: collectorFilter,
   time: 15000, // 15 seconds
});

您已经创建了一个组件收集器,因此正在收集组件交互(而不是反应)。需要明确的是,组件是按钮、选择菜单等(更多信息此处)。您需要改用

createReactionCollector()
函数。您链接的页面上列出了示例语法here

© www.soinside.com 2019 - 2024. All rights reserved.