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:
module.exports = {name: Events.GuildMemberUpdate,
async execute(oldMember: GuildMember, newMember: GuildMember)
{
console.log(oldMember) // Returns the member before role changes
console.log(newMember) // Returns undefined
}}
module.exports = {name: Events.GuildMemberUpdate,
async execute(oldMember: GuildMember, newMember: GuildMember)
{
console.log(oldMember) // Returns the member before role changes
console.log(newMember) // Returns undefined
}}
23 Replies
d.js toolkit
d.js toolkit8mo 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! - Marked as resolved by OP
Nxbula
Nxbula8mo ago
Node 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.
ShompiFlen
ShompiFlen8mo ago
show your event handler also any reason why you haven't updated to 14.13?
Nxbula
Nxbula8mo ago
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
ShompiFlen
ShompiFlen8mo ago
update when you can, just throwing it out there i dont think that will solve the issue yea send it i wanna see it
Nxbula
Nxbula8mo ago
No description
Nxbula
Nxbula8mo ago
In the index.js file
ShompiFlen
ShompiFlen8mo ago
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?
Nxbula
Nxbula8mo ago
Nope
Nxbula
Nxbula8mo ago
No description
Nxbula
Nxbula8mo ago
Works for every other event I've used, not sure why it doesn't work here.
ShompiFlen
ShompiFlen8mo ago
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 sus
Nxbula
Nxbula8mo ago
I understand that, but there are other events here where I use the exact same thing
Nxbula
Nxbula8mo ago
No description
Nxbula
Nxbula8mo ago
This works for example Exact same way exact same folder
ShompiFlen
ShompiFlen8mo ago
ok i see another issue
Nxbula
Nxbula8mo ago
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
ShompiFlen
ShompiFlen8mo ago
yes i think i just saw that now you have a typing issue (also)
Nxbula
Nxbula8mo ago
What is it?
ShompiFlen
ShompiFlen8mo ago
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() call
Nxbula
Nxbula8mo ago
Ah 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
ShompiFlen
ShompiFlen8mo ago
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
Nxbula
Nxbula8mo ago
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