【发布时间】:2020-11-07 15:31:15
【问题描述】:
我只想从一个语音通道控制我的 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}__**"`);
}
};
【问题讨论】:
-
我无法理解您的问题。我认为您希望消息作者仅在它们位于同一 VoiceChannel 时才断开机器人的连接?对吗?
-
是的,你是对的,只有当你和他在同一个语音频道时,我才想断开他的连接。
-
如果我能解决它与跳过命令相同,您可以从任何语音通道跳过歌曲...
标签: javascript node.js discord discord.js