我正在尝试执行带有随机嵌入的命令,但是当我触发命令时。它总是发送相同的选项,并且如果我重新加载bot,它将选择一个新选项,但是在我重新加载之前,它将保持不变。
我的代码顶部的“变量”:
var facts = ["Item1", "Item2", "Item 3", "Item 4" ];
var fact = Math.floor(Math.random() * facts.length);
命令:
if (message.content.startsWith (prefix + "random")){
var embed = new Discord.MessageEmbed()
.setTitle(":dvd: Sup stack overflow")
.setDescription(facts[fact])
.setColor("#f5980c")
.addField(invisible, field)
.setFooter(footer)
message.channel.send(embed)
console.log(`? ${message.author.tag} used saraiaiai`)
}
答案 0 :(得分:0)
每次收到消息时,您需要为fact
生成一个新值:
if (message.content.startsWith (prefix + "random")){
// notice this is here now
var fact = Math.floor(Math.random() * facts.length);
var embed = new Discord.MessageEmbed()
.setTitle(":dvd: Sup stack overflow")
.setDescription(facts[fact])
.setColor("#f5980c")
.addField(invisible, field)
.setFooter(footer)
message.channel.send(embed)
console.log(`? ${message.author.tag} used saraiaiai`)
}