【问题标题】:Discord.js Ignoring Other EmojisDiscord.js 忽略其他表情符号
【发布时间】:2021-01-08 03:00:37
【问题描述】:

我正在开发一个功能反应角色机器人。我正在尝试找出如何添加一个过滤器,该过滤器将忽略我分配的表情符号之外的其他表情符号。机器人工作正常,除非我或其他人尝试使用我分配的表情符号之外的表情符号与机器人做出反应。

client.on('message', message => {

    if(message.author.bot || message.embeds)

    embedMsg = message.embeds.find(msg => msg.title === 'Server Roles') ? message : undefined
      if(embedMsg) 
      {

      embedMsg.react('755602275963109536')
            .then
(reaction => reaction.message.react('755604749814071366'))
            .then(reaction => reaction.message.react('755605241067601960'))
            .then(reaction => reaction.message.react('755604978571280466'))
            .then(reaction => reaction.message.react('755604795292909589'))
            .then(reaction => reaction.message.react('755605048666620075'))
            .then(reaction => reaction.message.react('755604953229164594'))
            .then(reaction => reaction.message.react('755604994656436346'))
            .then(reaction => reaction.message.react('755605995195072603'))
            .then(reaction => reaction.message.react('755605032124022814'))
            .then(reaction => reaction.message.delete(20000))
            .then(msg => console.log("Deleted message"))
            .catch(() => console.error('One of the emojis failed to react.'));
            return;
      }

client.on('messageReactionAdd', (reaction, user) => {
    if (user.bot) return;
   
    var roleName = reaction.emoji.name;
    console.log(roleName);
    var role = reaction.message.guild.roles.find(
     role => role.name.toLowerCase() === roleName.toLowerCase()
    );
    var member = reaction.message.guild.members.find(
     (member) => member.id === user.id
    );
   //remove role
    if (member.roles.has(role.id)) {
     member
      .removeRole(role.id)
      .then((member) => {
       console.log(
        'Removed' + member.user.username + ' from the ' + role.name + ' role.'
       );
      })
      .catch((err) => console.error);
    //add role  
    } else {
     member
      .addRole(role.id)
      .then((member) => {
       console.log(
        'Added ' + member.user.username + ' to the ' + role.name + ' role.'
       );
      })
      .catch((err) => console.error);
    }
   });

【问题讨论】:

    标签: discord.js emoji


    【解决方案1】:

    您可以制作一系列接受的表情符号 ID,并根据给出的反应测试每个。

    const array = ['ID #1, 'ID #2', 'ID #3', 'etc.'];
    if (!array.includes(reaction.emoji.id)) return;
    

    【讨论】:

      猜你喜欢
      • 2020-09-10
      • 1970-01-01
      • 2010-10-12
      • 1970-01-01
      • 2021-01-21
      • 2021-01-28
      • 2018-01-05
      • 1970-01-01
      • 2014-04-03
      相关资源
      最近更新 更多