const commando = require('discord.js-commando');
const ytdl = require('ytdl-core');
function Play(connection, message)
{
var servers = servers[message.guild.id];
server.dispatcher = connection.playStream(ytdl(`${server.queue[0]}`, {filter: "audioonly"}));
server.queue.shift();
server.dispatcher.on("end", function(){
if(server.queue[0])
{
Play(connection, message);
}else
{
connection.disconnect();
}
});
}
class PlayCommand extends commando.Command
{
constructor(client)
{
super(client,{
name: 'play',
group: 'music',
memberName: 'play',
description: 'Plays music!'
});
}
async run(message, args)
{
if (!permissions.has('CONNECT') || !permissions.has('SPEAK')) {
return message.channel.send('I need the permissions to join and speak in your voice channel!');
}
if(message.member.voiceChannel)
{
if(!message.guild.voiceConnection)
{
if(!servers[message.guild.id])
{
var server = servers[message.guild.id];
servers[message.guild.id] = {queue: []}
}
message.member.voiceChannel.join()
.then(connection => {
var servers = servers[message.guild.id];
message.reply("Sucessfully Joined Channel!");
let validate = await ytdl.validateURL(args);
if(!validate) return message.channel.send('Sorry, Please input a **valid** url.');
server.queue.push(args);
Play(connection, message);
})
}
}
else{
message.reply("You must be in a voice channel to use that command! ")
}
console.log(message.author.username + ' Used a ' + 'music' + ' command \n');
}
}
module.exports = PlayCommand;
这是机器人上“播放”命令的代码。 该机器人的工作是使用ytdl库播放音乐。
我不确定问题出在哪里;起初,我以为它可能找不到该库或安装错误,所以我重新安装了所有库(ytdl-core,discord.js,discord.js-commando ...)
什么都没有!
我不太熟练使用Javascript,尤其是错误代码,因此非常感谢在正确方向上提供任何帮助或指导以帮助解决该问题!
这是我在这里的第一个问题,对于任何不一致之处,我深表歉意。
有关完整的错误代码:
(node:18216) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
答案 0 :(得分:0)
似乎servers
变量从未初始化过。确保它实际上包括正确的公会。