From 71da6e841dc80029609de50be568b352891f03d5 Mon Sep 17 00:00:00 2001 From: neru Date: Wed, 14 Jan 2026 21:26:48 -0300 Subject: [PATCH] feat: add better checks before joining --- src/commands/voice/join.ts | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/commands/voice/join.ts b/src/commands/voice/join.ts index 14488a3..3192df4 100644 --- a/src/commands/voice/join.ts +++ b/src/commands/voice/join.ts @@ -1,6 +1,7 @@ import { ChatInputCommandInteraction, GuildMember, + PermissionsBitField, SlashCommandBuilder } from 'discord.js'; import { Command } from '../../commands'; @@ -25,7 +26,7 @@ const cmd: Command = { return; } - if (!member.voice.channelId) { + if (!member.voice.channel || !member.voice.channelId) { interaction.reply('You are not currently on a voice channel'); return; } @@ -40,12 +41,35 @@ const cmd: Command = { return; } + const voiceChannel = member.voice.channel; + if (voiceChannel.userLimit != 0 && voiceChannel.members.size >= voiceChannel.userLimit) { + interaction.reply('Channel is full'); + return; + } + + const perms = voiceChannel.permissionsFor(me) + + if (!perms.has(PermissionsBitField.Flags.ViewChannel)) { + interaction.reply("I don't have permissions to see that channel") + return; + } + + if (!perms.has(PermissionsBitField.Flags.Connect)) { + interaction.reply("I don't have the permissions to join that channel"); + return; + } + + if (!perms.has(PermissionsBitField.Flags.Speak)) { + interaction.reply("I don't have permissions to speak on that channel") + return; + } + const voiceOptions: JoinVoiceChannelOptions & CreateVoiceConnectionOptions = - { - channelId: member.voice.channelId, - guildId: interaction.guild.id, - adapterCreator: interaction.guild.voiceAdapterCreator - }; + { + channelId: member.voice.channelId, + guildId: interaction.guild.id, + adapterCreator: interaction.guild.voiceAdapterCreator + }; const connection = await joinVoiceChannel(voiceOptions); if (!connection) {