不和谐音乐机器人由于某种原因停止工作

时间:2020-10-10 12:51:16

标签: javascript discord.js

基本上,我之前在这里问过我正在制造的这个机器人,当我开始编写音乐命令的代码时,它刚刚停止工作,它仍会在VSCode终端中打开,但是当我键入命令时,它说有一个参考错误说PREFIX未定义,这对代码很有帮助。


const client = new Discord.Client();

const ytdl = require("ytdl-core");

const prefix = '$';

var servers = {};

client.once('ready', () => {
    console.log('Bot is on!');
});


//Music Command



client.on(`message`, message => {

    let args = message.content.substring(PREFIX.length).split(" ");

    switch (args[0]) {
        case 'play':

            function play(connection, message){
                var server = servers[message.guild.id];

                server.dispatcher = connection.play(ytdl(server.queue[0], {filter: "audioonly"}));


                server.queue.shift();

                server.dispatcher.on("end", function(){
                    if(server.queue[0]){
                        play(connection, message);
                    }else {
                        connection.disconnect();
                    }
                });


            }

            if($args[1]){
                message.channel.send("provide a link!");
                return;
            }

            if($message.member.voice.channel){
                message.channel.send("you must be in a channel for me to join and play the music!");
                return;
            }

            if($servers[message.guild.id]) servers[message.guild.id] = {
                queue: []
            }

            var server = servers[message.guild.id];

            server.queue.push(args[1]);

            if ($message.member.voice.connection) message.member.voice.channel.join().then(function(connection){
                play(conncection, message);

            })

            
        }    
});```

0 个答案:

没有答案