Unable to get member data from users that have left / kicked

Hi, I am trying to get data from members who have left the discord server or have been kicked. But I keep getting undefined errors and I am unsure why here is my code. This only happen in sapphire
@ApplyOptions<Listener.Options>({ event: Events.GuildMemberRemove, name: 'Handle Guild Member Kick/Leave' })
export class MemberRemove extends Listener {
public async run(guild: Guild, member: PartialGuildMember) {
console.log(member); }
}
@ApplyOptions<Listener.Options>({ event: Events.GuildMemberRemove, name: 'Handle Guild Member Kick/Leave' })
export class MemberRemove extends Listener {
public async run(guild: Guild, member: PartialGuildMember) {
console.log(member); }
}
Solution:
1. Unrelated to Sapphire 2. You're implementing the event parameters incorrectly, see https://discord.js.org/#/docs/discord.js/main/class/Client?scrollTo=e-guildMemberRemove...
Discord.js
Discord.js is a powerful node.js module that allows you to interact with the Discord API very easily. It takes a much more object-oriented approach than most other JS Discord libraries, making your bot's code significantly tidier and easier to comprehend.
Jump to solution
6 Replies
Sawako
Sawako2y ago
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
tropic
tropicOP2y ago
Thank you also I def didn’t get timed out for calling my self dumb 😂 Sadly this did not work,
index.ts
export const client = new SapphireClient({
defaultPrefix: '!',
regexPrefix: /^(hey +)?bot[,! ]/i,
caseInsensitiveCommands: true,
logger: {
level: LogLevel.Debug
},
shards: 'auto',
intents: [
GatewayIntentBits.DirectMessageReactions,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.GuildBans,
GatewayIntentBits.GuildEmojisAndStickers,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.MessageContent
],
partials: [Partials.Channel, Partials.GuildMember, Partials.Message, Partials.Reaction, Partials.User],
loadMessageCommandListeners: true
});
index.ts
export const client = new SapphireClient({
defaultPrefix: '!',
regexPrefix: /^(hey +)?bot[,! ]/i,
caseInsensitiveCommands: true,
logger: {
level: LogLevel.Debug
},
shards: 'auto',
intents: [
GatewayIntentBits.DirectMessageReactions,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.GuildBans,
GatewayIntentBits.GuildEmojisAndStickers,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.MessageContent
],
partials: [Partials.Channel, Partials.GuildMember, Partials.Message, Partials.Reaction, Partials.User],
loadMessageCommandListeners: true
});
event.ts
@ApplyOptions<Listener.Options>({ event: Events.GuildMemberRemove, name: 'Handle Guild Member Kick/Leave' })
export class MemberRemove extends Listener {
public async run(guild: Guild, member: GuildMember) {
if (member.partial) {
const memberPartial = await member.fetch();
console.log(memberPartial.id)
}
}
}
event.ts
@ApplyOptions<Listener.Options>({ event: Events.GuildMemberRemove, name: 'Handle Guild Member Kick/Leave' })
export class MemberRemove extends Listener {
public async run(guild: Guild, member: GuildMember) {
if (member.partial) {
const memberPartial = await member.fetch();
console.log(memberPartial.id)
}
}
}
I also tried to pass in the PartialGuildMember Type, PartialUser Type and User Type to the event listener it self /listeners/events/member.js" TypeError: Cannot read properties of undefined (reading 'partial')
tropic
tropicOP2y ago
My intents are setup
Solution
Favna
Favna2y ago
1. Unrelated to Sapphire 2. You're implementing the event parameters incorrectly, see https://discord.js.org/#/docs/discord.js/main/class/Client?scrollTo=e-guildMemberRemove
Discord.js
Discord.js is a powerful node.js module that allows you to interact with the Discord API very easily. It takes a much more object-oriented approach than most other JS Discord libraries, making your bot's code significantly tidier and easier to comprehend.
tropic
tropicOP2y ago
I did not even notice I had the guild parameter there thank you
Want results from more Discord servers?
Add your server