设置每个用户对已发送消息的最大反应的问题

编程入门 行业动态 更新时间:2024-10-04 11:20:57

设置每个用户对已<a href=https://www.elefans.com/category/jswz/34/1754834.html style=发送消息的最大反应的问题"/>

设置每个用户对已发送消息的最大反应的问题

我正在制作一款黑手党游戏,要让它运行必须有一个投票系统,我想允许每个玩家投一票。

我的代码:

            const VotingMessage = await InnocentChannel.send(`**Player Numbers**\nPlayer 1: ${Mafia}\nPlayer 2: ${Doctor}\nPlayer 3: ${Innocent1}\nPlayer 4: ${Innocent2}\nWho would you like to vote for?\nYou have 1 minute for finish voting.`)
            await VotingMessage.react("1️⃣")
            await VotingMessage.react("2️⃣")
            await VotingMessage.react("3️⃣")
            await VotingMessage.react("4️⃣")

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

            client.on('messageReactionAdd', (reaction, user) => {

                if (user.id === client.user.id) return

                const VotingMessage = reaction

                const userCount = reactionCount.get(VotingMessage)
                userCount.set(user, (userCount.get(user) || 0) +1)

                if (userCount.get(user) > 1) {
                    reaction.users.remove(user)
                    InnocentChannel.send(`${user.id}, you've already voted for a player, remove a vote to be able to vote for someone else.`)

                }

            })

            client.on('messageReactionRemove', (reaction, user) => {
                if (user.id === client.user.id) return

                const VotingMessage = reaction
                const userCount = reactionCount.get(VotingMessage)
                userCount.set(user, reactionCount.get(VotingMessage).get(user) -1)
            })

当前错误:

userCount.set(用户,(userCount.get(用户)|| 0)+1)。类型错误:无法读取未定义的属性(读取“设置”)

回答如下:

更多推荐

设置每个用户对已发送消息的最大反应的问题

本文发布于:2024-05-31 03:26:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1771222.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发送消息   用户

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!