メッセージに制限し、ユーザーの反応

マヌエルCELLI:

私はシンプルな建物だポーリングボット私はメッセージにユーザーごとの反応の最大数を実装しようとしている今、JavaScriptでの確執のために。

例えば、我々は投票の質問には、以下のオプションがあるとします。

質問?

  1. オプションA

  2. オプションB

  3. オプションC

  4. オプションD

  5. オプションE

それぞれの「オプションは、」ボットから与えられたメッセージに反応ですが、私は、ユーザーがことを確認するに反応することはできないより 3これらのオプションの。

  • 思考の私の列車は作ることだったmessageReactionAddリスナーをして、ユーザーが反応させたときに4th time、「あなたはすでに投票してきたように彼にメッセージを送信する、最後の反応を削除し3 times、再度、投票への反応を削除してください」。
  • それでも、私は総反応数を見つけるために、オブジェクト間を移動しようとしてこだわっているユーザーごとに、私は総反応数を見つけることができ絵文字ごとにそれは私が必要なものではありません。

誰かが私にこの上でいくつかの洞察を与えることができますか?

EDIT

コードは、メッセージを送信するために使用されます。

Embed = new Discord.MessageEmbed()
                .setColor(0x6666ff)
                .setTitle(question)
                .setDescription(optionsList);

                message.channel.send(Embed).then(messageReaction => {

                for (var i = 0; i < options.length; i++){
                    messageReaction.react(emojiAlphabet[i][0]);
                }

                message.delete().catch(console.error);
              });
桜の花 :

これを試して:

const {Collection} = require('discord.js')

// the messages that users can only react 3 times with
const polls = new Set()
// Collection<Message, Collection<User, number>>: stores how many times a user has reacted on a message
const reactionCount = new Collection()

// when you send a poll add the message the bot sent to the set:
polls.add(message)

client.on('messageReactionAdd', (reaction, user) => {
  // edit: so that this does not run when the bot reacts
  if (user.id === client.user.id) return

  const {message} = reaction

  // only do the following if the message is one of the polls
  if (polls.has(message)) {
    // if message hasn't been added to collection add it
    if (!reactionCount.get(message)) reactionCount.set(message, new Collection())
    // reaction counts for this message
    const userCount = reactionCount.get(message)
    // add 1 to the user's reaction count
    userCount.set(user, (userCount.get(user) || 0) + 1)

    if (userCount.get(user) > 3) {
      reaction.users.remove(user)
      // <@!id> mentions the user (using their nickname if they have one)
      message.channel.send(`<@!${user.id}>, you've already voted 3 times, please remove a reaction to vote again.`)
    }
  }
})

client.on('messageReactionRemove', (reaction, user) => {
  // edit: so that this does not run when the bot reacts
  if (user.id === client.user.id) return

  const {message} = reaction
  const userCount = reactionCount.get(message)
  // subtract 1 from user's reaction count
  if (polls.has(message)) userCount.set(user, reactionCount.get(message).get(user) - 1)
})

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=303582&siteId=1