feat: add better checks before joining
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
ChatInputCommandInteraction,
|
ChatInputCommandInteraction,
|
||||||
GuildMember,
|
GuildMember,
|
||||||
|
PermissionsBitField,
|
||||||
SlashCommandBuilder
|
SlashCommandBuilder
|
||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
import { Command } from '../../commands';
|
import { Command } from '../../commands';
|
||||||
@@ -25,7 +26,7 @@ const cmd: Command = {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!member.voice.channelId) {
|
if (!member.voice.channel || !member.voice.channelId) {
|
||||||
interaction.reply('You are not currently on a voice channel');
|
interaction.reply('You are not currently on a voice channel');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -40,6 +41,29 @@ const cmd: Command = {
|
|||||||
return;
|
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 =
|
const voiceOptions: JoinVoiceChannelOptions & CreateVoiceConnectionOptions =
|
||||||
{
|
{
|
||||||
channelId: member.voice.channelId,
|
channelId: member.voice.channelId,
|
||||||
|
|||||||
Reference in New Issue
Block a user