Discord.js-反应收集器出现问题

时间:2020-08-10 13:22:12

标签: node.js discord.js emoji collectors

那是我的一个小功能代码,但user.id每次都未定义。而且我不知道为什么。

const bot = new Discord.Client();

bot.on('message', function(message) {
  if(message.author.bot) return;
  if(message.content === prefix+'react'){
  message.react('?');
  const filter = (reaction, user) => {
    return reaction.emoji.name === '?' && user.id != bot.user.id;
  };
  
  const collector = message.createReactionCollector(filter, { time: 5000 });
  
  collector.on('collect', (reaction, user) => {
    message.channel.send(`Collected ${reaction.emoji.name} from ${user.id}`);
  });
  
  collector.on('end', collected => {
    console.log(`Collected ${collected.size} items`);
  });
 }
});

1 个答案:

答案 0 :(得分:0)

尝试:

const filter = (reaction, user) => {
        return ['?'].includes(reaction.emoji.name) && user.id !== bot.user.id;
};

类似的东西对我有用