0
const Discord = require('discord.js');
const serverQueue = require('./play.js');
const ytdl = require('ytdl-core');

module.exports.run = async (bot, message, args) => {
 const voiceChannel = message.member.voice.channel;
 if (!voiceChannel)
  return message.channel.send(
   '**You need to be in a Voice Channel to play music :no_entry:!**'
  );
 const permissions = voiceChannel.permissionsFor(message.client.user);
 if (!permissions.has('CONNECT'))
  return message.channel.send(
   '**I have Insufficient permissions :no_entry:!**'
  );
 if (!permissions.has('SPEAK'))
  return message.channel.send(
   '**I have Insufficient permissions :no_entry:!**'
  );

 const songInfo = await ytdl.getInfo(args[0]);
 const song = {
  title: songInfo.title,
  url: songInfo.video_url,
 };

 if (!serverQueue) {
  const queueConstruct = {
   textChannel: message.channel,
   voiceChannel: voice.channel,
   connection: null,
   songs: [],
   volume: 5,
   playing: true,
  };
  queue.set(message.guild.id, queueConstruct);

  queueConstruct.songs.push(song);

  try {
   var connection = await voiceChannel.join();
   queueConstruct.connection = connection;
   play(message.guild, queueConstruct.songs[0]);
  } catch (error) {
   console.log(`There was an error connecting to the Voice Channel: ${error}`);
   queue.delete(message.guild.id);
   return message.channel.send(
    `There was an error connecting to the Voice Channel: ${error}`
   );
  }
 } else {
  serverQueue.songs.push(song);
  return message.channel.send(
   `**${song.title} has been added to the queue :white_check_mark:!**`
  );
 }
 return undefined;

 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('finish', () => {
    serverQueue.songs.shift();
    play(guild, serverQueue.songs[0]);
   })
   .on('error', (error) => {
    console.log(error);
   });
  dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);
 }
};

TypeError:无法读取未定义的属性“推送”

请忽略: 敏捷的棕色狐狸跳过懒惰的狗,敏捷的棕色狐狸跳过懒惰的狗,敏捷的棕色狐狸跳过懒惰的狗,敏捷的棕色狐狸跳过懒惰的狗,敏捷的棕色狐狸跳过懒惰的狗。

4

1 回答 1

0

您遇到的错误意味着您要推送的数组未定义或不存在。 console.log(queue construct)尝试在 push 语句之前检查 queueConstruct 中的数据是否显示在控制台上。

如果它显示未定义,请尝试将您的 const 更改为 var。

于 2020-09-05T03:51:57.127 回答