0

机器人成功连接到语音频道,但没有从我输入的 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');
  }
}  

谁能确定造成这种情况的潜在原因?

4

1 回答 1

0

据我所知,您使用的是 Discord.js V11,这不是推荐的版本(V12)

从文档看来,也许您必须将可选参数传递给 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);

如果这不起作用,可以在此处找到 Discord.js 的支持服务器。他们在 3 月正式迁移到 V12,但他们可能仍会帮助您

于 2020-08-31T00:35:34.087 回答