简体   繁体   English

Discord bot 没有加入我所在的语音频道

[英]Discord bot not joining the voice channel i'm in

I'm trying to code my own music bot but it is not joining the voice channel where I'm in. Everything else is working fine.我正在尝试编写我自己的音乐机器人,但它没有加入我所在的语音频道。其他一切正常。 I think that I should install a specific thing using npm but I don't know if that's right or not, i'm not sure so can somebody please tell me what should I do to fix this problem...我认为我应该使用 npm 安装一个特定的东西,但我不知道这是否正确,我不确定所以有人可以告诉我我应该怎么做才能解决这个问题......

Here's My Code :这是我的代码:

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


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

            if(!message.member.voiceChannel) {
                message.channel.send("You must be in a voice channel to use this command!");
                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.voice.channel.join().then(function(connection) {
                play(connection, message);
            })

        break;
    }

});

I think you are using the discord.js version 12+, in this version the voiceConnection property is removed from the GuildMember class.我认为你正在使用的discord.js版本12+,在这个版本中voiceConnection属性是从去除GuildMember类。

You should try the following -您应该尝试以下操作 -

message.member.voice.channel.join()

I think that the line code where you define args is typo, You're trying to define 'args' with a 'substring' method but this is a mistake, try change it to 'slice' , that should fix your problem.我认为您定义 args 的行代码是错字,您正在尝试使用 'substring' 方法定义 'args' 但这是一个错误,尝试将其更改为 'slice' ,这应该可以解决您的问题。 Unless you tried other commands and they worked.除非您尝试了其他命令并且它们起作用了。

Try change it to that line of code:尝试将其更改为该行代码:

let args = message.content.slice(prefix.length).split(" ");让 args = message.content.slice(prefix.length).split(" ");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM