ITMISS
2022-12-18 16:12:59
例子:結果為 1 = 他回應:結果為 1,下次幸運!結果是20 = 他回答:結果是20,恭喜!現在的代碼是:const Discord = require('discord.js');module.exports.run = async (client, message, args) => { var response = [Math.floor(Math.random() * ((20 - 1) + 1) + 1)]; message.channel.send("The result is " + response + "!").then().catch(console.error); if (response === 20) { message.channel.send("The result is " + response + ", congratulations!").then().catch(console.error); } if (response === 1) { message.channel.send("The result is " + response + ", luckier next time!").then().catch(console.error);}}我試過了,但他只是回答“(“結果是”+響應+“!”)”......
2 回答

吃雞游戲
TA貢獻1829條經驗 獲得超7個贊
如前所述,您沒有正確分配隨機值。您還可以創建一個響應對象,從而不再需要多個 if 語句。
const Discord = require('discord.js');
module.exports.run = async (client, message, args) => {
var result = Math.floor(Math.random() * ((20 - 1) + 1) + 1);
let response = {
1: ", luckier next time!",
2: ...
.
.
.
19: ...
20: ", congratulations!"
}
message.channel.send("The result is " + result + response[result]).then().catch(console.error);
}
}

拉丁的傳說
TA貢獻1789條經驗 獲得超8個贊
看起來你已經將你的 var 設置response
為一個數組,但是你正在使用===
.
嘗試刪除語句周圍的方括號:
var response = Math.floor(Math.random() * ((20 - 1) + 1) + 1);
添加回答
舉報
0/150
提交
取消