滄海一幻覺
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")}
}
添加回答
舉報
0/150
提交
取消
