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

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

不和諧.js“通道”未定義錯誤消息

不和諧.js“通道”未定義錯誤消息

滄海一幻覺 2022-08-04 10:12:11
我最近對使用Javascript和node.js制作一個不和諧的機器人產生了興趣。我正在嘗試創建一個旋轉虛擬“彩票”的命令,并發送一條消息,告訴用戶他們是否收到了任何東西。(這是我的代碼:)`function lotteryCommand(arguments, receivedMessage){/*note: receivedMessage is defined as the command (for my bot, it's e!spin)   and arguments is the part following the command (for this particular bit of code,   it's merits, so the user sends "e!spin merits")*/    if (arguments == "merits"){        setTimeout(randomlottery1, 1000);    }    else{receivedMessage.channel.send("Message here")}    }這是另一個函數。這是它停止工作的地方  function randomlottery1(arguments, receivedMessage){    let respond;    let responses = [        //some random phrases here    ]    respond = responses[Math.floor(Math.random() * responses.length)]    receivedMessage.channel.send(respond)}由于某種原因我無法理解,它在第二次識別函數中無法識別,但它在代碼中較早地識別了命令。我在這里做錯了什么嗎?謝謝。channelreceivedMessage.channel.sendrandomlottery1
查看完整描述

1 回答

?
守候你守候我

TA貢獻1802條經驗 獲得超10個贊

我認為你的問題是你沒有向你的函數傳遞任何參數,你可以通過這樣做輕松修復它:


function lotteryCommand(arguments, receivedMessage){



/*note: receivedMessage is defined as the command (for my bot, it's e!spin) 

  and arguments is the part following the command (for this particular bit of code, 

  it's merits, so the user sends "e!spin merits")*/


    if (arguments == "merits"){

            // dont forget to pass in the required parameters while executing your function (parameter1, parameter2)

            setTimeout(randomlottery1(arguments, receivedMessage), 1000);

    }

    else{receivedMessage.channel.send("Message here")}

    }


查看完整回答
反對 回復 2022-08-04
  • 1 回答
  • 0 關注
  • 110 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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