机器人已成功连接到语音通道,但未播放我键入的URL中的歌曲,代码为:
if(message.content.startsWith(prefix + "join"))
{
message.channel.send("Entrando a " + message.member.voiceChannel);
if (message.member.voiceChannel)
{
const permissions = message.member.voiceChannel.permissionsFor(message.client.user);
if (!permissions.has('CONNECT'))
{
return message.channel.send('No me puedo conectar a ese canal')
}
if (!permissions.has('SPEAK')) {
return message.channel.send('No puedo hablar en ese canal')
}
let connection = await message.member.voiceChannel.join();
let dispatcher = connection.playStream(ytdl('https://www.youtube.com/watch?v=PLRrL9OsAF8&t=18s'))
.on('start', () => {
message.reply('Empieza la musica');
})
.on('end', () => {
message.reply('Termino la musica');
message.member.voiceChannel.leave();
})
.on('error', error => {
message.reply('Error al intentar reproducir la cancion');
});
dispatcher.setVolumeLogarithmic(5 / 5);
}
else
{
message.reply('Tenes que estar dentro de un chat de voz');
}
}
任何人都可以找出潜在原因吗?
答案 0 :(得分:0)
据我所知,您正在使用不是推荐版本(V12)的Discord.js V11
尽管从文档看来,也许您必须将可选参数传递给ytdl
// Play streams using ytdl-core
const ytdl = require('ytdl-core');
const streamOptions = { seek: 0, volume: 1 };
voiceChannel.join()
.then(connection => {
const stream = ytdl('https://www.youtube.com/watch?v=XAWgeLF9EVQ', { filter : 'audioonly' });
const dispatcher = connection.playStream(stream, streamOptions);
})
.catch(console.error);
如果这样不起作用,可以找到here的Discord.js的支持服务器。他们于3月正式移至V12,但仍可能为您提供帮助