【问题标题】:ReferenceError: message is not defined popping up randomlyReferenceError:消息未定义随机弹出
【发布时间】:2019-10-18 02:39:02
【问题描述】:

所以我正在制作一个 discord 机器人并尝试使用 discord.js、node-opus 和 ytdl-core 来实现音乐。但是随机地,在执行命令时(主要是 >>stop),我会得到一个完全停止命令的 ReferenceError,而再尝试一次,不做任何更改,命令将成功完成。有什么帮助吗?

Bot Snippet |下面是执行命令时随机出现的错误。

(node:11740) UnhandledPromiseRejectionWarning: ReferenceError: message is not defined
at StreamDispatcher.<anonymous> (C:\Users\###\Desktop\real_bot_code\main.js:286:7)
at StreamDispatcher.emit (events.js:200:13)
at StreamDispatcher.destroy (C:\Users\###\Desktop\real_bot_code\node_modules\discord.js\src\client\voice\dispatcher\StreamDispatcher.js:294:10)
at AudioPlayer.destroyCurrentStream (C:\Users\###\Desktop\real_bot_code\node_modules\discord.js\src\client\voice\player\AudioPlayer.js:77:18)
at VoiceConnection.<anonymous> (C:\Users\###\Desktop\real_bot_code\node_modules\discord.js\src\client\voice\player\AudioPlayer.js:42:53)
at Object.onceWrapper (events.js:288:20)
at VoiceConnection.emit (events.js:205:15)
at VoiceConnection.disconnect (C:\Users\###\Desktop\real_bot_code\node_modules\discord.js\src\client\voice\VoiceConnection.js:311:10)
at VoiceChannel.leave (C:\Users\###\Desktop\real_bot_code\node_modules\discord.js\src\structures\VoiceChannel.js:142:69)
at Client.<anonymous> (C:\Users\###\Desktop\real_bot_code\main.js:179:31)

对不起,如果这是一个不好的例子,我对 stack 和 discord.js 很陌生。

【问题讨论】:

    标签: discord.js


    【解决方案1】:

    问题:在您的play() 函数中,您指的是message,但它并未在其scope 中定义。
    解决方案:message 作为参数传递,例如...

    function play(message, song) {
      const guild = message.guild;
    
      // rest of function code
    }
    

    ...然后在您客户的message 事件中,像这样调用函数...

    play(message, queueConstruct.songs[0]);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-22
      • 2021-06-03
      • 1970-01-01
      • 2019-12-29
      • 2018-11-24
      • 2021-03-01
      • 2022-01-05
      相关资源
      最近更新 更多