【问题标题】:Discord.js "channel" not defined error messageDiscord.js“通道”未定义错误消息
【发布时间】:2020-05-07 05:36:55
【问题描述】:

我最近开始对使用 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)
}

由于某种原因,我无法理解,它在receivedMessage.channel.send second 时间,在randomlottery1 函数中无法识别channel,但它在代码前面识别了该命令。我在这里做错了什么吗?谢谢。

【问题讨论】:

    标签: javascript node.js discord discord.js


    【解决方案1】:

    我认为您的问题是您没有将任何参数传递给您的函数,您可以通过这样做轻松修复它:

    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")}
        }
    

    【讨论】:

    • 谢谢。实际上,它停止工作是因为我指定了不需要的参数。还是谢谢你!
    猜你喜欢
    • 2018-10-23
    • 2020-09-10
    • 2020-06-27
    • 2021-06-20
    • 1970-01-01
    • 1970-01-01
    • 2017-08-22
    • 2021-06-03
    • 2021-12-27
    相关资源
    最近更新 更多