Wolf_Yout
@Wolf_Yout

Почему не воспроизводиться музыка?

Прописываю !play <ссылка>
Вот код:
const discord = Discord.js
//Начало всех комманд
client.on('message', async message => {
  if (message.author.bot) return;
  if (!message.content.startsWith(prefix)) return;
  
  const serverQueue = queue.get(message.guild.id);
  
  if (message.content.startsWith(`${prefix}play`)) {
  execute(message, serverQueue);
  return;
  } else if (message.content.startsWith(`${prefix}skip`)) {
  skip(message, serverQueue);
  return;
  } else if (message.content.startsWith(`${prefix}stop`)) {
  stop(message, serverQueue);
  return;
  } else {

  }
  });
  
  async function execute(message, serverQueue) {
  const args = message.content.split(' ');
  
  const voiceChannel = message.member.voice.channel  
  if (!voiceChannel) return message.channel.send('You need to be in a voice channel to play music!');
  const permissions = voiceChannel.permissionsFor(message.client.user);
  if (!permissions.has('CONNECT') || !permissions.has('SPEAK')) {
  return message.channel.send('I need the permissions to join and speak in your voice channel!');
  }
  
  const songInfo = await ytdl.getInfo(args[1]);
  const song = {
  title: songInfo.title,
  url: songInfo.video_url,
  };
  
  if (!serverQueue) {
  const queueContruct = {
  textChannel: message.channel,
  voiceChannel: voiceChannel,
  connection: null,
  songs: [],
  volume: 5,
  playing: true,
  };
  
  queue.set(message.guild.id, queueContruct);
  
  queueContruct.songs.push(song);
  
  try {
  var connection = await voiceChannel.join();
  queueContruct.connection = connection;
  play(message.guild, queueContruct.songs[0]);
  } catch (err) {
  console.log(err);
  queue.delete(message.guild.id);
  return message.channel.send(err);
  }
  } else {
  serverQueue.songs.push(song);
  console.log(serverQueue.songs);
  return message.channel.send(`${song.title} has been added to the queue!`);
  }
  
  }
  
  function skip(message, serverQueue) {
  if (!message.member.voiceChannel) return message.channel.send('You have to be in a voice channel to stop the music!');
  if (!serverQueue) return message.channel.send('There is no song that I could skip!');
  serverQueue.connection.dispatcher.end();
  }
  
  function stop(message, serverQueue) {
  if (!message.member.voiceChannel) return message.channel.send('You have to be in a voice channel to stop the music!');
  serverQueue.songs = [];
  serverQueue.connection.dispatcher.end();
  }
  
  function play(guild, song) {
  const serverQueue = queue.get(guild.id);
  
  if (!song) {
  serverQueue.voiceChannel.leave();
  queue.delete(guild.id);
  return;
  }
  
  const dispatcher = serverQueue.connection.play(ytdl(song.url))
  .on('end', () => {
  console.log('Music ended!');
  serverQueue.songs.shift();
  play(guild, serverQueue.songs[0]);
  })
  .on('error', error => {
  console.error(error);
  });
  dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);
  }

Бот присоединился ко мне в Голосовой канал
И в консоли вылетает ошибка:
Error: input stream: No video id found: undefined
    at Object.exports.getVideoID (C:\Users\shits\Desktop\MEE9\node_modules\ytdl-core\lib\url-utils.js:63:11)
    at Function.exports.<computed> [as getInfo] (C:\Users\shits\Desktop\MEE9\node_modules\ytdl-core\lib\info.js:476:29)
    at ytdl (C:\Users\shits\Desktop\MEE9\node_modules\ytdl-core\lib\index.js:19:8)
    at play (C:\Users\shits\Desktop\MEE9\index.js:114:50)
    at execute (C:\Users\shits\Desktop\MEE9\index.js:79:3)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
  • Вопрос задан
  • 104 просмотра
Пригласить эксперта
Ответы на вопрос 1
TheSnegok
@TheSnegok
at play (C:\Users\shits\Desktop\MEE9\index.js:114:50)
at execute (C:\Users\shits\Desktop\MEE9\index.js:79:3)
Вот отсюда ошибки, пересмотри код, мне кажется дело в play(message.guild, queueContruct.songs[0]);
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы