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•13mo 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•13mo 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
Melio•13mo ago
Bad type 🙂 AuditLogEvent.MemberDisconnect @Aiwoz
Melio
Melio•13mo ago
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•13mo ago
Thank you but how can you tell if he leaves the voice or if he gets disconnected?
Melio
Melio•13mo ago
MemberDisconnected = MemberLeave the AudioLogEntry so check if executor or not
Aiwoz
AiwozOP•13mo ago
With if(action) ?
Melio
Melio•13mo ago
yes
Aiwoz
AiwozOP•13mo ago
Thank you. ^^
Want results from more Discord servers?
Add your server