APIInteractionDataResolvedGuildMember does not have id

While fetching for member using interaction.options.getMember('member') it gives two types - GuildMember|APIInteractionDataResolvedGuildMember out of which the second one literally doesn't have member's snowflake ID I saw this https://discord-api-types.dev/api/discord-api-types-v10/interface/APIInteractionDataResolvedGuildMember and confirmed that it really doesn't have id field How am I supposed to fetch such a member (basically type guard the member)? My package.json
"dependencies": {
"@sapphire/decorators": "^6.0.0",
"@sapphire/discord.js-utilities": "6.0.4",
"@sapphire/framework": "^4.2.2",
"@sapphire/pieces": "^3.6.1",
"@sapphire/plugin-logger": "^3.0.1",
"@sapphire/plugin-subcommands": "^4.0.0",
"@sapphire/utilities": "^3.11.0",
"colorette": "^2.0.19",
"discord-api-types": "^0.37.36",
"discord.js": "^14.8.0",
"firebase-admin": "^11.5.0",
"yaspr": "^1.0.2"
},
"dependencies": {
"@sapphire/decorators": "^6.0.0",
"@sapphire/discord.js-utilities": "6.0.4",
"@sapphire/framework": "^4.2.2",
"@sapphire/pieces": "^3.6.1",
"@sapphire/plugin-logger": "^3.0.1",
"@sapphire/plugin-subcommands": "^4.0.0",
"@sapphire/utilities": "^3.11.0",
"colorette": "^2.0.19",
"discord-api-types": "^0.37.36",
"discord.js": "^14.8.0",
"firebase-admin": "^11.5.0",
"yaspr": "^1.0.2"
},
No description
2 Replies
MRDGH2821
MRDGH2821OP2y ago
I could definitely do this -
const member = interaction.options.getMember('member') as GuildMember;
const member = interaction.options.getMember('member') as GuildMember;
But I want to keep this as last resort.
Favna
Favna2y ago
function isGuildMember(data: GuildMember | APIInteractionDataResolvedGuildMember): data is GuildMember {
return data instanceof GuildMember;
}
function isGuildMember(data: GuildMember | APIInteractionDataResolvedGuildMember): data is GuildMember {
return data instanceof GuildMember;
}
const member = interaction.options.getMember('member');

if (!isGuildMember(member)) {
throw new Error('....');
}

// now it's a GuildMember, alternatively flip the if statement and keep it in inside the if statement
const member = interaction.options.getMember('member');

if (!isGuildMember(member)) {
throw new Error('....');
}

// now it's a GuildMember, alternatively flip the if statement and keep it in inside the if statement
Want results from more Discord servers?
Add your server