我只想从一个语音通道控制我的Discord机器人,但是你可以将他与任何语音通道断开连接。我想让他仅在您与他在语音通道中时断开连接。这是我的代码:
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}__**"`);
}
};
答案 0 :(得分:0)
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.