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
d.js toolkit
d.js toolkit3mo ago
- 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
mallusrgreat
mallusrgreat3mo ago
if interaction.inCachedGuild() is true, then it's cached
avaze
avaze3mo ago
Ahh 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)?
mallusrgreat
mallusrgreat3mo ago
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;
avaze
avaze3mo ago
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
mallusrgreat
mallusrgreat3mo ago
yes
avaze
avaze3mo ago
Okay thanks a lot!