反应收集器似乎不适合我,我希望能够收集消息或嵌入的反应。
这是我创建的斜线命令
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