0
votes

I'm working on a discord bot that plays music. I have managed to get the bot to leave the channel, but anyone in the server can disconnect it.

I have tried to add an if statement that requires the command author's voiceChannel connection to be equal to the bot's voiceChannel connection in that guild.

if(client.guildChannel.voiceChannel == message.author.voiceChannel)
        {
            message.guild.voiceConnection.disconnect(); 
        }

this returns:

Property "voiceChannel" cannot be read of undefined.

I can't find anything on the documentation that defines which voice channel the bot is connected to in which guild.

1
either guildChannel or author is undefined.Daniel A. White

1 Answers

0
votes

To find on which channel your bot is, use message.guild.me.voiceChannel. It return the current voiceChannel of the bot. Otherwise, client.voiceConnections.find(val => val.channel.guild.id === message.guild.id); should also work.