.getMember() with Typescript
I saw that
options.getMember()
sometimes doesn't return a GuildMember.
How can I filter this case out?14 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 OPWith a condition statement
There is no second parameter to specify whether the option is required or not to narrow it down as someone can simply paste in the ID of a user who is not in the guild that the command was ran in, resulting in you getting a user for them but not a member
Ahhh, scratch that, you must be referring to the "raw" object
:method: CommandInteraction#inCachedGuild()
@14.16.3
Indicates whether this interaction is received from a cached guild.uhm, I really meant "When is the second type returned?" 😅
When the guild isn’t cached
When the interaction you receive is from a guild that's not cached
and then addtionally "How can I filter this?"
When does this happen? I have all guilds cached usually.
User-installable app
Added to a guild without the
bot
scope
No Guilds intentAlso custom cache settings/removing guilds from cache manually
This typeguard filters that out
that.... is dumb. Understandable, but a problem I think.
Could I just fetch the guild when a guild isn't cached or something similar?
If your app actually has access to the guild, sure
if it isn't a user installable app and you have the Guilds intent (most of the time you do) then you could just return if it isn't cached, instead of having to handle that case manually
okay, thank you both very much! ^^
it's not a user-app
so that would not be the cause