0
votes

I want to control my Discord bot only from one voice channel, but you can just disconnect him from any voice channel. I want to make him disconnect only if you are with him in voice channel. Here is my code:

const { Command } = require('discord.js-commando');

module.exports = class LeaveCommand extends Command {
    constructor(client) {
        super(client, {
            name: 'leave',
            aliases: ['l'],
            group: 'music',
            memberName: 'leave',
            description: 'Ies din voice channel :(.',
            guildOnly: true,
        });
    }

    run(message) {
     var voiceChannel = message.member.voice.channel;
    if (!voiceChannel) {
      message.reply('Intra pe un voice channel si incearca din nou');
      return;
    }
        const connection = this.client.voice.connections.get(message.guild.id);
        if (!connection) return message.reply('Nu sunt intr-un voice channel.');
        connection.channel.leave();
        return message.reply(`Am iesit din voice channel-ul - "**__${connection.channel.name}__**"`);
    }
};
1
I'm having trouble understanding your question. I think you want the message author to disconnect the bot only if they are in the same VoiceChannel? Is that right?Jakye
Yes, you are right, i want to disconnect him only if you are on the same voice channel as him.RazvanDam
Same as skip command if i would resolve it, you can skip the song from any voice channel...RazvanDam

1 Answers

0
votes
if (!message.guild.voice || !message.guild.voice.channel) return message.channel.send(`I am not connected to any Voice channels.`); // Checking if the bot is connected to any voice channels.
if (!message.member.voice || !message.member.voice.channel) return message.channel.send(`You are not in any voice channels.`); // Checking if the message author is conencted to a voice channel.
if (message.member.voice.channelID !== message.guild.voice.channelID) return message.channel.send(`You need to be in the ${message.guild.voice.channel} channel.`); // Checking if the bot's voice channel is the same as message author's channel.

message.channel.send(`Command executed successfully.`); // Executing the command.