From cd9d5248acae76a48930d77842cf7845fb1fbe0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81vila?= Date: Wed, 15 Sep 2021 23:12:48 +0100 Subject: Join the message sender's channel if possible --- src/utils/channels.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/utils') diff --git a/src/utils/channels.ts b/src/utils/channels.ts index b27f5a6..f46e469 100644 --- a/src/utils/channels.ts +++ b/src/utils/channels.ts @@ -1,4 +1,4 @@ -import {Guild, VoiceChannel, User} from 'discord.js'; +import {Guild, VoiceChannel, User, GuildMember} from 'discord.js'; export const isUserInVoice = (guild: Guild, user: User): boolean => { let inVoice = false; @@ -20,6 +20,18 @@ export const getSizeWithoutBots = (channel: VoiceChannel): number => channel.mem return s; }, 0); +export const getMemberVoiceChannel = (member?: GuildMember): [VoiceChannel, number] | null => { + const channel = member?.voice?.channel; + if (channel && channel.type === 'voice') { + return [ + channel, + getSizeWithoutBots(channel) + ]; + } + + return null; +}; + export const getMostPopularVoiceChannel = (guild: Guild): [VoiceChannel, number] => { interface PopularResult { n: number; -- cgit v1.2.3