亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

當骰子的結果是 20 和 1 時,如何讓機器人說出不同的反應?

當骰子的結果是 20 和 1 時,如何讓機器人說出不同的反應?

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);  


   }

}


查看完整回答
反對 回復 2022-12-18
?
拉丁的傳說

TA貢獻1789條經驗 獲得超8個贊

看起來你已經將你的 var 設置response為一個數組,但是你正在使用===.

嘗試刪除語句周圍的方括號:

var response = Math.floor(Math.random() * ((20 - 1) + 1) + 1);


查看完整回答
反對 回復 2022-12-18
  • 2 回答
  • 0 關注
  • 108 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號