Files
xiao/commands/util-public/join.js
T
lilyissillyyy 5f925590f8 Fix
2025-09-14 20:09:49 -04:00

39 lines
1.5 KiB
JavaScript

const Command = require('../../framework/Command');
const { PermissionFlagsBits } = require('discord.js');
const { joinVoiceChannel } = require('@discordjs/voice');
const VoiceDispatcher = require('../../structures/VoiceDispatcher');
const perms = [PermissionFlagsBits.Connect, PermissionFlagsBits.Speak, PermissionFlagsBits.ViewChannel];
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-public',
description: 'Joins your voice channel.',
guildOnly: true,
guarded: true,
userPermissions: [PermissionFlagsBits.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(perms)) {
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 VoiceDispatcher(voiceChannel));
return msg.reply(`Joined **${voiceChannel.name}**!`);
}
};