Transform a APIInteractionDataResolvedGuildMember into a GuildMember
Hello there,
I am beginning with discord.js and typescript. To ensure type safety, i want to make sure that the object returned by a
interaction.options.getMember()
is a GuildMember and not a APIInteractionDataResolvedGuildMember in order to later perform various operations. So i've began to write a function to fetch the GuildMember if needed but APIInteractionDataResolvedGuildMember does not have a user property so i can't have the id for fetching...
How should i deal with it ? Or can i safely assume that in the context of slash commands in guild i will always have a GuildMember object ?
Here the function that i wrote :
Thanks !8 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 OP:method: BaseInteraction#inCachedGuild
@14.15.3
Indicates whether or not this interaction is both cached and received from a guild.The easiest way to fix this would be to simply ensure that the interaction is from a cached guild with this typeguard, which will then narrow the typing for
getMember()
to specifically be a GuildMember structure and not raw dataOkay, and if the guild is not cached can i cache it manually ?
Do you have the Guilds intent?
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
Yeah i have it
Thanks to both then
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View