Interaction CacheType in Typescript
Hey everyone,
I've started rewriting my bot in Typescript, and i'm running into problems with the generic Interaction type.
interaction.member
seems to be either GuildMember
or APIInteractionGuildMember
, depending if the interaction is of CacheType "raw" or "cached". What exactly is the difference between those two? Which type will actually come back from the .on("interactionCreate", ...)
listener, or how do i best go about validating it?7 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 OPif
interaction.inCachedGuild()
is true, then it's cachedAhh okay thanks, is there an easy way to always convert it to a cached one?
is it just
guild = i.inCachedGuild() ? i.guild : client.guilds.cache.get(i.guildId)
?inCachedGuild() checks exactly that
if you have Guilds intent you can either cast the interaction as Interaction<"cached"> or just throw in
if(!interaction.inCachedGuild()) return;
Ahh okay so it is dependant on intents? Cause i will always have the guilds intent, casting it as "cached" would be a lot easier
yes
Okay thanks a lot!