我正在尝试编写“猜数字”游戏。这是我的代码:
if (message.content === `${Math.floor(Math.random() * 6) + 1}`) {
const channel = message.client.channels.cache.get('755124858744078468');
const Member = message.channel.guild.roles.cache.get('725350761751511061');
const rightEmbed = new Discord.MessageEmbed()
.setColor('DARK_GREEN')
.setTitle(`${message.author.username} got the right number!`)
.setTimestamp()
.setFooter('PlanetMc Development');
message.channel.send({ embed: rightEmbed });
console.log(`${message.author.username} got the right number!`);
channel.updateOverwrite(Member, { SEND_MESSAGES: false });
message.channel.send('&reload guess');
}
但是它不起作用,并且不返回任何错误。我应该收到消息,因为我尝试了1到6之间的每个数字。
答案 0 :(得分:-1)
问题在于,只要有消息,Math.floor(Math.random() * 6) + 1
就会重置。
这意味着无论何时发出client.on('message'),它都会生成一个新号码。
您应该选择使用a message collector还是数据库来存储公会的当前编号。您可以选择