因此,我正在制作一个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来说,这还不是很新。
答案 0 :(得分:0)
问题:在您的play()
函数中,您指的是message
,但未在其scope中定义。
解决方案:例如,将message
作为参数传递...
function play(message, song) {
const guild = message.guild;
// rest of function code
}
...,然后在客户的message
事件中,像这样调用函数...
play(message, queueConstruct.songs[0]);