无法生成 0 到 10 之间的随机数
Trouble generating a random number between 0 and 10
我在 discord 机器人中工作,特别是在速率命令中,它应该 return:
"I would rate (thing to be rated) (random number)/10."
但是它 returns:
"I would rate (thing to be rated) [object Undefined]/10."
client.on('message', message => {
if(message.content.startsWith (prefix + "rate")) {
if(message.content.slice(prefix.length + 4) === ""){
message.channel.send("Give me something to rate");
}
else
message.channel.send("I would rate" + "**" +
message.content.slice(prefix.length + 4) + "**" + " " +
toString(Math.floor(Math.pow(Math.random, 10))) + "/10");
}
可能有什么问题?
您需要合并以下代码(考虑到您想要返回整数):
Math.floor(Math.random()*11)
放弃 Math.pow()
方法。
根据@Geert-Jan 的建议进行编辑
我在 discord 机器人中工作,特别是在速率命令中,它应该 return:
"I would rate (thing to be rated) (random number)/10."
但是它 returns:
"I would rate (thing to be rated) [object Undefined]/10."
client.on('message', message => {
if(message.content.startsWith (prefix + "rate")) {
if(message.content.slice(prefix.length + 4) === ""){
message.channel.send("Give me something to rate");
}
else
message.channel.send("I would rate" + "**" +
message.content.slice(prefix.length + 4) + "**" + " " +
toString(Math.floor(Math.pow(Math.random, 10))) + "/10");
}
可能有什么问题?
您需要合并以下代码(考虑到您想要返回整数):
Math.floor(Math.random()*11)
放弃 Math.pow()
方法。
根据@Geert-Jan 的建议进行编辑