ReferenceError:服务器未定义

时间:2019-01-15 08:47:16

标签: javascript discord.js commando

运行命令时,我得到:ReferenceError: servers is not defined.,但没有发现任何错误。

我是否缺少包裹或其他物品?

const commando = require('discord.js-commando');
const YTDL = require("ytdl-core");

function Play(connection, message)
{
    var server = 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 PlayMusicCommand extends commando.Command
{
    constructor(client)
    {
        super(client,{
            name: 'play',
            group: 'music',
            memberName: 'play',
            description: 'Plays music'
        });
    }

    async run(message, args)
    {
        if(message.member.voiceChannel)
        {
            if(!message.guild.VoiceConnection)
            {
                if(!servers[message.guild.id])
                {
                    servers[message.guild.id] = {queue: []}
                }
                message.member.voiceChannel.join()
                    .then(connection =>{
                        var server = servers[message.guild.id];
                        message.reply("Succesfully Joined");
                        server.queue.push(args);
                        Play(connection, message);
                    })
            }
        }
        else
        {
            message.reply("You must be in a voice channel to invite me Baka!");
        }
    }
}

module.exports = PlayMusicCommand;

1 个答案:

答案 0 :(得分:0)

您尝试通过servers访问servers[message.guild.id]数组变量。 但是在代码中没有定义为servers的变量,因此解释器会准确地告诉您。 您可能忘记了导入。