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:无法读取未定义的属性“推送”
请忽略: 敏捷的棕色狐狸跳过懒惰的狗,敏捷的棕色狐狸跳过懒惰的狗,敏捷的棕色狐狸跳过懒惰的狗,敏捷的棕色狐狸跳过懒惰的狗,敏捷的棕色狐狸跳过懒惰的狗。