From 7fe865ad98197b52e59cb226b41c5a3c980b3186 Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Sun, 28 Jan 2024 18:33:22 +0100 Subject: [PATCH] detect users joining/leaving voice channels --- events/voiceStateUpdate.js | 16 ++++++++++++++++ index.js | 1 + 2 files changed, 17 insertions(+) create mode 100644 events/voiceStateUpdate.js diff --git a/events/voiceStateUpdate.js b/events/voiceStateUpdate.js new file mode 100644 index 0000000..3473ee0 --- /dev/null +++ b/events/voiceStateUpdate.js @@ -0,0 +1,16 @@ +import { Events } from 'discord.js'; + +export const name = Events.VoiceStateUpdate; +export async function execute(oldState, newState) { + console.debug('[DEBUG] Voice State Update'); + + const change = (!!oldState.channel) ^ (!!newState.channel); + if (!change) return; + + const guild = newState.guild.name; + const member = newState.member.user.username; + const state = newState.channel ? 'joined' : 'left'; + const channel = (oldState.channel ?? newState.channel).name; + + console.debug(`[DEBUG] User '${member}' ${state} channel '${channel}' in guild '${guild}'.`); +} diff --git a/index.js b/index.js index 8b7aee2..a08a3bf 100644 --- a/index.js +++ b/index.js @@ -18,6 +18,7 @@ const runClient = (commands, events) => { intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, + GatewayIntentBits.GuildVoiceStates, GatewayIntentBits.GuildMessageReactions ], partials: [Partials.Message, Partials.Reaction]