14.9.0 Client.on('guildMemberUpdate') Problem
Hello! I am on discord js 14.9.0 and I am trying to use client.on('guildMemberUpdate') within an event file. The documentation says that there are two parameters, oldMember, and newMember. When I try to use the paramaters, I get the oldMember parameter working, but the newMember parameter returns undefined. Code snippet:
23 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!
- ✅
Marked as resolved by OPNode version is v16.5.1
I have Guild Member intents, like I said, I do recieve the oldMember, but newMember returns undefined.
Feel free to ping me if you know the problem.
show your event handler
also any reason why you haven't updated to 14.13?
Lack of awareness of that being a thing
I can send the event handler, but just so you know the event is being registered and I do recieve the logs when a role is updated
update when you can, just throwing it out there i dont think that will solve the issue
yea send it i wanna see it
In the index.js file
do you see the issue here
can you tell me where are you passing the event arguments
oldMember
and newMember
to the event execute()
function?Nope
Works for every other event I've used, not sure why it doesn't work here.
ok so you are a little confused here
you define this execute function with these two arguments
oldMember, newMember
, that part is fine
the part that is not fine is your event handler
you are only passing the client to this functions
that "works in other events" is a little susI understand that, but there are other events here where I use the exact same thing
This works for example
Exact same way
exact same folder
ok i see another issue
Also keep in mind, it isn't returning the client, the event is registering, it is returning a GuildMember for oldMember, but it is returning undefined for newMember
yes i think i just saw that now
you have a typing issue
(also)
What is it?
this
client.on(event.name, (client:Client)
is assuming you will receive a Client object on every event and passing that to the execute function, this is not right
you will receive a different argument type depending on the event you are receiving
that said, you are only passing 1 argument to the guildMemberUpdate event
thats why your newMember is undefined
I think you can easily fix this if you instead of doing (client: Client) =>
you do (...args: any)
then pass ...args
to the execute()
callAh I see
I copied the code for event handling a while back, not sure if it was updated recently
But I see it there now
Honestly no clue how it magically worked all this time, but I really appreciate the help
i doubt this would've work at any point to be honest, i mean it does work for some events that only require 1 argument, but for those that receive more than 1 it probably wouldn't have worked anyway
Yeah, I have a backend so most the discord bot operations are more simplistic, like on ready or on message, so I've never had to deal with this problem
It's worked for a year now though so very surprised