Audit Logs : VoiceStatUpdates

Hey ! How to separate the logs of a member who is disconnected and a member who leaves himself ?
9 Replies
d.js toolkit
d.js toolkit•2y ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Aiwoz
AiwozOP•2y ago
if (oldChannel && !newChannel) {



const { AuditLogEvent } = require('discord.js');

const fetchedLogs = await (oldState, newState).guild.fetchAuditLogs({
limit: 1,
type: 'MEMBER_DISCONNECT',
});

const log = fetchedLogs.entries.first();
const { executor } = log;

console.log(executor);
if (oldChannel && !newChannel) {



const { AuditLogEvent } = require('discord.js');

const fetchedLogs = await (oldState, newState).guild.fetchAuditLogs({
limit: 1,
type: 'MEMBER_DISCONNECT',
});

const log = fetchedLogs.entries.first();
const { executor } = log;

console.log(executor);
Melio | « Le K »
Bad type 🙂 AuditLogEvent.MemberDisconnect @Aiwoz
Melio | « Le K »
https://discordjs.guide/popular-topics/audit-logs.html#who-deleted-a-message Same code,
const { AuditLogEvent, Events } = require('discord.js');

client.on(Events.GuildAuditLogEntryCreate, async auditLog => {
// Define your variables.
// The extra information here will be the channel.
const { action, extra: channel, executorId, targetId } = auditLog;

// Check only for deleted messages.
if (action !== AuditLogEvent.MemberDisconnect) return;

// Ensure the executor is cached.
const executor = await client.users.fetch(executorId);

// Ensure the author whose message was deleted is cached.
const target = await client.users.fetch(targetId);

// Log the output.
console.log(`member disconnected from ${channel}.`);
});
const { AuditLogEvent, Events } = require('discord.js');

client.on(Events.GuildAuditLogEntryCreate, async auditLog => {
// Define your variables.
// The extra information here will be the channel.
const { action, extra: channel, executorId, targetId } = auditLog;

// Check only for deleted messages.
if (action !== AuditLogEvent.MemberDisconnect) return;

// Ensure the executor is cached.
const executor = await client.users.fetch(executorId);

// Ensure the author whose message was deleted is cached.
const target = await client.users.fetch(targetId);

// Log the output.
console.log(`member disconnected from ${channel}.`);
});
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
Aiwoz
AiwozOP•2y ago
Thank you but how can you tell if he leaves the voice or if he gets disconnected?
Melio | « Le K »
MemberDisconnected = MemberLeave the AudioLogEntry so check if executor or not
Aiwoz
AiwozOP•2y ago
With if(action) ?
Aiwoz
AiwozOP•2y ago
Thank you. ^^

Did you find this page helpful?