Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/427.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript TypeError:无法设置属性';调度员';未定义的_Javascript_Node.js_Discord_Discord.js - Fatal编程技术网

Javascript TypeError:无法设置属性';调度员';未定义的

Javascript TypeError:无法设置属性';调度员';未定义的,javascript,node.js,discord,discord.js,Javascript,Node.js,Discord,Discord.js,我正在做一个discord音乐机器人,我编写了以下代码: module.exports = { name: 'play', aliases: ['p'], description: 'Play a song', guildOnly: true, execute(message, args) { const ytdl = require("ytdl-core"); var servers

我正在做一个discord音乐机器人,我编写了以下代码:

module.exports = {
    name: 'play',
    aliases: ['p'],
    description: 'Play a song',
    guildOnly: true,

    execute(message, args) {
        const ytdl = require("ytdl-core");
        
        var servers = {}
        var server = servers[message.guild.id];
        var queue = []
        
        function play(connection, message){
            var server = servers[message.guild.id];
            var str = String(message)
            var key = str.split(/\s/);


            // If user inputs skip, skip the song
            try {
                server.dispatcher = connection.play(ytdl(queue[0], {filter: "audio"}));
            } catch (error) {
                if (key[1] == "skip") {
                    server.dispatcher.destroy();
                } else {
                    message.channel.send("You need to provide a correct url!");
                    console.log(error)
                    }
                return;
                }

            queue.shift();

            server.dispatcher.on("finish", function(){
            if (queue[0]){
                play(connection, message);
            } else {
                connection.disconnect();
            }
        });
        }
//------------function ends here-------------------

        if (!args[0]) {
            message.channel.send("You need to provide a link!");
            return;
        }

        if (!message.member.voice.channel){
            message.channel.send("You must be in a voice channel to use this command!");
            return;
        }

        queue.push(args[0]);

        if (!message.guild.voiceConnection) message.member.voice.channel.join().then(function(connection){
            play(connection, message);
        });
}}
每当我运行代码时,它总是告诉我错误

TypeError:无法设置未定义的属性“dispatcher”

错误发生在第22行,即

server.dispatcher=connection.play(ytdl(队列[0],{filter:“audio”}))

据我所知,当一个变量被声明但没有被赋值时,它会抛出错误。但是我只是在上面赋值,我不明白为什么它会给我这个错误

顺便说一句,歌曲队列和跳过功能从来都不起作用,所以如果有人能帮我纠正错误,我将非常感激,非常感谢

var servers = {}
var server = servers[message.guild.id];
由于服务器是一个空对象,您不应该期望它具有
message.guild.id
属性