为了账号安全,请及时绑定邮箱和手机立即绑定

不和谐.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 关注
  • 87 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信