Discordbot无法使用ytdl-core播放音乐,可能已过时

时间:2020-04-09 22:53:44

标签: discord.js

这是我的代码,有人可以帮忙吗?下面是所有代码,但出问题的是,该漫游器实际上并未进入语音通道。有人可以帮忙,我找不到错误了!

const Discord = require('discord.js');
const ytdl = require('ytdl-core');
const bot = new Discord.Client();
const prefix = "m!";
const token = "Some Token;

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();
});
}

var servers = {};

bot.on("ready", function(){
console.log("Milky Music is Online!!");
});

bot.on("message", function(message) {
if(message.author.equals(bot.user)) return;
if(!message.content.startsWith(prefix)) return;

var args = message.content.substring(prefix.length).split(" ");

switch(args[0].toLowerCase()){
case "play":
    if(!args[1]){
        message.channel.send("Please add a link");
        return;
    }
    if(!message.member.voiceChannel){
        message.channel.send("You have to be in a Voice Channel");
        return;
    }
    if(!servers[message.guild.id]) servers[message.guild.id] = {
        queue: []
    };
    var server = servers[message.guild.id];

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

    if(!message.guild.voiceConnection) 
 message.member.voiceChannel.join().then(function(connection){
        play(connection, message);
    });
    break;
default:
    message.channel.send("Unknown Command");
    break;
}

});

bot.login(token)

这是所有代码,如果您需要更多详细信息,我会回答。因此,请您提供帮助或提供新代码?请帮忙!!

0 个答案:

没有答案