Getting the executor from Audit Logs
Hello i have this code:
But the
userWhoDidIt
is undefined
26 Replies
- 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!sounds like it was unable to find an audit log entry for that type
Oh, i will try again it tomorrow! I was checking docs and only found
MemberUpdate
So i made the change, but now my code is:
But it cannot find the user using the IDoffender
appears to be the entry itself
<GuildAuditLogsEntry>.id
is the id of the entry, not the target's id
<GuildAuditLogsEntry>.targetId
existsunless you were looking to fetch the executor?
your var names are a little confusing
regardless
<GuildAuditLogsEntry>.executorId
also existsSo it should be
sure
1 other question, the
MemberRoleUpdate
works only when i give a role, or does it also work when i remove a role?
Coz right now it only works whenever i give someone a role, when removed, then it does nothing.,if it does nothing, then likely this code isn't executing
it wouldn't be due to the audit log event type
regardless, the answer is
MemberRoleUpdate
is also for removing rolesIf you aren't getting any errors, try to place
console.log
checkpoints throughout your code to find out where execution stops.
- Once you do, log relevant values and if-conditions
- More sophisticated debugging methods are breakpoints and runtime inspections: learn moreAlso, the
MemebrRoleUpdate
only executes when someone is chaging ROLEs on user, nothing else, right?I'm not exactly sure what else you'd expect an event type of that name to be for
But if i have it in the
guildMemberUpdate
event, then if i only want the role updates i can do
?this doesn't really tell me a ton about the rest of your logic
but assuming that's the only check, you may find a false positive when an older audit log entry exists for a member update unrelated to roles
What i ment is that, guildMemberUpdate event also gets triggered when someone updates somoenes name right?
I only want to go through when the evnt is triggered and a ROLE is given
I understand that
please read my message
Oki 🙂
I got that yeah
Thanks
Also 1 more question hehe
If i wanna remove all bot's roles expect their own bot role coz das impossible, how can i do that?
you can access the client member for a given guild with
<Guild>.members.me
you can completely overwrite a member's role list with <GuildMember>.roles.set()
since set
accepts a Collection
as well, you can simply pass a filtered <GuildMember>.roles.cache
members are also unable to remove their own highest role
So how do i define the bot's own role in the guild?, with the
.me
?as mentioned previously,
.me
is the client member for the given guild
it's a GuildMember
<GuildMember>.roles.botRole
exists, but in general you can also just check for <Role>.managed
when filtering rolesSo when i'd like my bot, to remove another bots all roles expect the bot's own role, how shall i do it?
<GuildMember>.roles.botRole
exists, but in general you can also just check for<Role>.managed
when filtering roles
But could i do something like this:
So now i filter from botAllRoles and then i remove the rest?