generated from Baipyrus/DiscordJS-Template
detect users joining/leaving voice channels
This commit is contained in:
parent
0edf46856a
commit
7fe865ad98
16
events/voiceStateUpdate.js
Normal file
16
events/voiceStateUpdate.js
Normal file
@ -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}'.`);
|
||||||
|
}
|
1
index.js
1
index.js
@ -18,6 +18,7 @@ const runClient = (commands, events) => {
|
|||||||
intents: [
|
intents: [
|
||||||
GatewayIntentBits.Guilds,
|
GatewayIntentBits.Guilds,
|
||||||
GatewayIntentBits.GuildMessages,
|
GatewayIntentBits.GuildMessages,
|
||||||
|
GatewayIntentBits.GuildVoiceStates,
|
||||||
GatewayIntentBits.GuildMessageReactions
|
GatewayIntentBits.GuildMessageReactions
|
||||||
],
|
],
|
||||||
partials: [Partials.Message, Partials.Reaction]
|
partials: [Partials.Message, Partials.Reaction]
|
||||||
|
Loading…
Reference in New Issue
Block a user