Move Log

I'm trying to create a move log like this:
client.on('voiceStateUpdate', async (oldMember, newMember) => {
if (oldMember.channelId !== null && newMember.channelId !== null) {
if (oldMember.channelId === newMember.channelId) return;
const fetchedLogsMove = await newMember.guild.fetchAuditLogs({
limit: 1,
type: AuditLogEvent.MemberMove,
});
const LogMove = fetchedLogsMove.entries.first();
if (!LogMove) return;
const { executorId } = LogMove;
if (Date.now() - LogMove.createdTimestamp < 3000) {
channel.send(`<@${newMember.id}> was moved!`).catch(err => { console.log(err) });
}
}
})
client.on('voiceStateUpdate', async (oldMember, newMember) => {
if (oldMember.channelId !== null && newMember.channelId !== null) {
if (oldMember.channelId === newMember.channelId) return;
const fetchedLogsMove = await newMember.guild.fetchAuditLogs({
limit: 1,
type: AuditLogEvent.MemberMove,
});
const LogMove = fetchedLogsMove.entries.first();
if (!LogMove) return;
const { executorId } = LogMove;
if (Date.now() - LogMove.createdTimestamp < 3000) {
channel.send(`<@${newMember.id}> was moved!`).catch(err => { console.log(err) });
}
}
})
but if the admin moved someone else to the same channel it's gonna just edit the users value without creating a new log so it won't log.
No description
16 Replies
d.js toolkit
d.js toolkit14mo 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!
Forhand.
Forhand.OP14mo ago
because I'm using LogMove.createdTimestamp < 3000 to check if the user was moved or he joined the channel by himself, is there another way to check that?
chewie
chewie14mo ago
LogMove.createdTimestamp < 3000 will always be false createdTimestamp represents the unix milliseconds starting from 1970
Forhand.
Forhand.OP14mo ago
it's actually not always, it'll be true when the admin moved user to channel he didn't in last 10 mins so how to check if the user moved or he joined the channel by himself?
chewie
chewie14mo ago
no, it wont
Forhand.
Forhand.OP14mo ago
another way instead of LogMove.createdTimestamp < 3000
chewie
chewie14mo ago
you would have to substract LogMove.createdTimestamp from a new date and check if that is < 3000
Forhand.
Forhand.OP14mo ago
yes I forgot to type the new date here but I did in my code but this way isn't good actually so I'm asking if anyone can help me with another way to detect if he moved to channel or not?
chewie
chewie14mo ago
use the voiceStateUpdate event and check oldState.channel vs newState.channel
Forhand.
Forhand.OP14mo ago
but still won't be accurate right?
chewie
chewie14mo ago
why not that will show you when someone switched channels instantly
Forhand.
Forhand.OP14mo ago
yes I did it here but the thing is to detect if the user was moved or he joined the channel by himself you can get just the executor from the logs without the target
chewie
chewie14mo ago
And how do you make sure the user was actually moved?
Forhand.
Forhand.OP14mo ago
no I said that cuz I can't make sure that the user got moved or not through logs if u only can get the executor and the channel from the logs it won't be accurate yes that's my point with an accurate way
chewie
chewie14mo ago
Like Qjuh told you, check the users value of the entry
Forhand.
Forhand.OP14mo ago
so u r saying that I can get the target that got moved from the logs? okay I’ll try this tomorrow then I’ll come back here
Want results from more Discord servers?
Add your server