![](/img/trans.png)
[英]Error running discord bot with discord.js-musicbot-addon: Cannot find module 'm3u8stream/lib/parse-time'
[英]Trying to make the discord.js-musicbot-addon work. When music is about to play i get this error
TypeError: Cannot read property 'play' of undefined
at C:\Users\pink\Desktop\IwtdB0t_v.7\node_modules\discord.js-musicbot-addon\index.js:1474:41
at processTicksAndRejections (internal/process/task_queues.js:93:5)
我尝试将每个 discord.js v11 命令更新为 discord.js v12 但从 playStream 更改为播放后仍然出现错误。 有什么想法可能导致这种情况吗?
这似乎是 discord.js-musicbot-addon 库的问题,因此很遗憾您无能为力。
我认为导致错误的代码(删除了一些不相关的代码,删除了缩进并添加了注释以提高可读性):
new Promise((resolve, reject) => {
const voiceConnection = client.voice.connections.find(val => val.channel.guild.id == msg.guild.id);
// This line here is what (I believe) is ultimately causing the error.
// Collection#find returns undefined, not null, when an item cannot be found.
// Because this uses strict equality (===), an undefined voiceConnection (e.g.
// the bot hasn't connected to a voice channel yet) won't trigger this code.
if (voiceConnection === null) {
// attempts to connect to the voice channel
/* ... */
} else {
// The promise is resolved with a potentially undefined voiceConnection.
resolve(voiceConnection);
}
}).then(connection => {
// retrieves the video to play
/* ... */
try {
/* ... */
// This line is where the error is. When connection is undefined, it throws
// the error "Cannot read property 'play' of undefined"
let dispatcher = connection.play(ytdl(video.url, {
filter: 'audioonly',
quality: 'highestaudio'
}), {
bitrate: mjusicbot.bitRate,
volume: (queue.volume / 100)
})
请注意,discord.js-musicbot-addon 在 NPM 上已弃用,不再受支持。 从回购:
该项目不再受支持,也不再支持 function。 不要使用这个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.