发送消息的最大反应的问题"/>
设置每个用户对已发送消息的最大反应的问题
我正在制作一款黑手党游戏,要让它运行必须有一个投票系统,我想允许每个玩家投一票。
我的代码:
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)。类型错误:无法读取未定义的属性(读取“设置”)
更多推荐
设置每个用户对已发送消息的最大反应的问题
发布评论