Files
xiao/commands/util-voice/join.js
T
Dragon Fire d97fa2f9d9 Fix lint
2024-03-20 16:21:48 -04:00

38 lines
1.3 KiB
JavaScript

const Command = require('../../framework/Command');
const { joinVoiceChannel } = require('@discordjs/voice');
const Dispatcher = require('../../structures/Dispatcher');
module.exports = class JoinCommand extends Command {
constructor(client) {
super(client, {
name: 'join',
aliases: ['join-voice-channel', 'join-vc', 'join-voice', 'join-channel', 'connect'],
group: 'util-voice',
memberName: 'join',
description: 'Joins your voice channel.',
guildOnly: true,
guarded: true,
userPermissions: ['CONNECT']
});
}
run(msg) {
const voiceChannel = msg.member.voice.channel;
if (!voiceChannel) return msg.reply('Please enter a voice channel first.');
if (!voiceChannel.permissionsFor(this.client.user).has(['CONNECT', 'SPEAK', 'VIEW_CHANNEL'])) {
return msg.reply('I\'m missing the "Connect", "Speak", or "View Channel" permission for this channel.');
}
if (!voiceChannel.joinable) return msg.reply('Your voice channel is not joinable.');
if (this.client.dispatchers.has(msg.guild.id)) {
return msg.reply('I am already in a voice channel.');
}
joinVoiceChannel({
channelId: voiceChannel.id,
guildId: voiceChannel.guild.id,
adapterCreator: voiceChannel.guild.voiceAdapterCreator
});
this.client.dispatchers.set(msg.guild.id, new Dispatcher(voiceChannel));
return msg.reply(`Joined **${voiceChannel.name}**!`);
}
};