GUILD_MEMBER_UPDATE - oldMember & newMember

Stackoverflow ( https://stackoverflow.com/questions/66175307/discord-js-guildmemberupdate-not-being-called-except-on-bot-user-changes ) is telling me guild member update event get oldMember and newMember as parameter.
client.on('guildMemberUpdate', (oldMember, newMember) => {
// Fire if user has a role
if (newMember.roles.cache.some(r => r.name === "TEST_ROLE")) {
try {
// stuff
} catch(err) {
// stuff
}
}
})
client.on('guildMemberUpdate', (oldMember, newMember) => {
// Fire if user has a role
if (newMember.roles.cache.some(r => r.name === "TEST_ROLE")) {
try {
// stuff
} catch(err) {
// stuff
}
}
})
DiscordJS is telling me they provide it as well. But how to access it in sapphire ? The run() function in a listener has only the client available. https://discord.js.org/#/docs/discord.js/main/class/Client?scrollTo=e-guildMemberUpdate
export class GuildMemberUpdateListener extends Listener {
public constructor(context: Listener.Context, options: Listener.Options) {
super(context, {
...options,
emitter: container.client.ws,
event: 'GUILD_MEMBER_UPDATE'
});
}

public async run(client: Client) {
}
}
export class GuildMemberUpdateListener extends Listener {
public constructor(context: Listener.Context, options: Listener.Options) {
super(context, {
...options,
emitter: container.client.ws,
event: 'GUILD_MEMBER_UPDATE'
});
}

public async run(client: Client) {
}
}
Solution:
Not sure. Check your intents I guess. Haven't dealt with this event in a long time. Regardless, it's more of a DJS question because sapphire literally does absolutely nothing for events. We don't for example proxy forward them or anything, we also just use client.on(...) essentially.
Jump to solution
10 Replies
Favna
Favna2y ago
It doesn't only have client available, not sure where you got that from. The parameters match exactly with what DJS says. For the record this is like asking: When using client.on(... only client is available:
client.on('guildMemberUpdate', (client) => { })
client.on('guildMemberUpdate', (client) => { })
roest
roest2y ago
Favna
Favna2y ago
I don't see what's so hard to understand here. The first parameter is not client
roest
roest2y ago
sorry if this question is stupid so i understand first parameter is oldMember second is newMember
Favna
Favna2y ago
export class GuildMemberUpdateListener extends Listener {
public constructor(context: Listener.Context, options: Listener.Options) {
super(context, {
...options,
emitter: container.client.ws,
event: 'GUILD_MEMBER_UPDATE'
});
}

public async run(oldMember: Guild member, newMember: GuildMember) {
}
}
export class GuildMemberUpdateListener extends Listener {
public constructor(context: Listener.Context, options: Listener.Options) {
super(context, {
...options,
emitter: container.client.ws,
event: 'GUILD_MEMBER_UPDATE'
});
}

public async run(oldMember: Guild member, newMember: GuildMember) {
}
}
Yes, exactly like the djs docs tell you it is. Like I said, I have no idea where you even got the idea from that it would be client.
roest
roest2y ago
yea its a missunderstanding from documentation. And as i checked paramters... parameter 2 is alway: 0 https://www.sapphirejs.dev/docs/Guide/listeners/creating-your-own-listeners
roest
roest2y ago
Favna
Favna2y ago
The reason the example shows client is because it's the ready event and that's the only parameter the ready event receives
Solution
Favna
Favna2y ago
Not sure. Check your intents I guess. Haven't dealt with this event in a long time. Regardless, it's more of a DJS question because sapphire literally does absolutely nothing for events. We don't for example proxy forward them or anything, we also just use client.on(...) essentially.
roest
roest2y ago
You already helped me what to exspect from this event. Thank you very much i will proceed debugging myself.