Add user voice channel checks

This commit is contained in:
2022-01-30 22:42:00 +07:00
parent da56d51ba0
commit 16c03c3f4f
6 changed files with 125 additions and 27 deletions
+27 -2
View File
@@ -1,5 +1,5 @@
import { Message, CommandInteraction, Interaction, VoiceChannel } from "discord.js";
import { getEmotes, makeSuccessEmbed, makeProcessingEmbed, sendMessage, sendMessageOrInteractionResponse, makeInfoEmbed } from "../../utils/DiscordMessage";
import { getEmotes, makeSuccessEmbed, makeErrorEmbed, sendMessage, sendMessageOrInteractionResponse, makeInfoEmbed } from "../../utils/DiscordMessage";
import DiscordProvider from "../../providers/Discord";
import Users from "../../services/Users"
import Environment from "../../providers/Environment";
@@ -12,6 +12,24 @@ const EMBEDS = {
description: `Left the voice channel`,
user: (data instanceof Interaction) ? data.user : data.author
});
},
USER_NOT_IN_VOICECHANNEL: (data: Message | Interaction) => {
return makeErrorEmbed({
title: `You need to be in the voice channel first!`,
user: (data instanceof Interaction) ? data.user : data.author
});
},
NO_MUSIC_PLAYING: (data: Message | Interaction) => {
return makeErrorEmbed({
title: `There are no music playing`,
user: (data instanceof Interaction) ? data.user : data.author
});
},
USER_NOT_IN_SAME_VOICECHANNEL: (data: Message | Interaction) => {
return makeErrorEmbed({
title: `You are not in the same voice channel!`,
user: (data instanceof Interaction) ? data.user : data.author
});
}
}
@@ -40,11 +58,18 @@ export default class Leave {
if(!data.guildId) return;
const channel: any = isMessage ? data.member.voice.channel : DiscordProvider.client.guilds.cache.get((data as Interaction).guildId!)!.members.cache.get((data as Interaction).user.id)?.voice.channel;
if (!data.member.voice.channel)
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.USER_NOT_IN_VOICECHANNEL(data)] });
if(!channel) return;
let instance = DiscordMusicPlayer.getGuildInstance(data.guildId);
if(!instance) return;
if(!instance)
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NO_MUSIC_PLAYING(data)] });
if(instance.voiceChannel.id !== data.member.voice.channel.id)
return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(data)] });
DiscordMusicPlayer.destoryGuildInstance(data.guild?.id!);