【问题标题】:Can a discord bot count how many reaction a user got on there profile?不和谐的机器人可以计算用户在个人资料上得到多少反应吗?
【发布时间】:2020-12-31 09:23:55
【问题描述】:

所以我想知道一个不和谐的机器人是否可以计算图像有多少反应,并根据用户得到的反应给他们一个 xp 或 -xp 从那里级别有点像 reddits upvote 和 downvote 系统

【问题讨论】:

    标签: javascript discord discord.js


    【解决方案1】:

    我建议你在发布一个很长的可回答问题之前先上网看看。例如在反应页面上的 discord.js 指南 -> Link

    是的,discord bot 在发送消息后可以创建一个消息收集器,在其中收集有关消息反应的所有信息(计数、用户、反应名称和 ID)

    【讨论】:

      【解决方案2】:

      您可以使用messageReactionAdd 事件和Map

      // create the map (use any name)
      const karma = new Map();
      
      // set up the event
      client.on('messageReactionAdd', (reaction, user) => {
      
        // check if the message has an attachment. you can add any other conditions here as well,
        // such as the channel the message was sent in, etc.
        // (to fetch the message object, use `reaction.message`
        if (!reaction.message.attachments) return;
        
        // you should also create a filter so that this will only trigger for certain reactions (upvotes and downvotes)
        const upvote = '?' // for example
        const downvote = '?' // for example
        
        if (![upvote, downvote].includes(reaction.emoji.name)) return;
      
        // check if the map has an entry for this user. if not, make one
        if (!karma.has(user.id)) 
           karma.set(user.id, reaction.emoji.name === upvote ? 1 : -1) // either give the new user 1 or -1 karma depending on the emote
        
        // otherwise, increment/decrement karma total depending on emoji
        else reaction.emoji.name === upvote ? karma.get(user.id)++ : karma.get(user.id)--
      
      });
      

      那么,只要你想得到某人的“业力”,你就可以使用:

      karma.get('<ID Here>')
      

      【讨论】:

      • 当我尝试用一​​个简单的业力命令获得赞成票的数量时,它只是说“”“[object] 也给我一个错误,说用户未定义
      • 您不能在messageReactionAdd 事件之外使用user 变量,只需输入用户ID(例如,您可以使用message.author.id 等)。另外,请提供返回[object Object]的代码行
      猜你喜欢
      • 2020-09-16
      • 2019-02-13
      • 1970-01-01
      • 1970-01-01
      • 2020-08-26
      • 1970-01-01
      • 2020-05-25
      • 2022-01-26
      • 2021-11-25
      相关资源
      最近更新 更多