When is interaction "cached" for user context menu commands?
Hey all, I'm writing a user context menu command (alongside some other ones that already exist) and wanted to see if I could save myself from writing some code by assuming the interaction type is cached.
In what cases are interactions not cached?
10 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!cc @fops
i'm not sure what you mean by "interaction type is cached"
what are you trying to do?
respond to a command?
where does the cache come into play?
I'm referencing the object
Interaction which has a CacheType of cached , raw, or undefined. If the Interaction is cached, then I can assume things like guild and targetMember exist, and for targetMember specifically I can assume that it's a GuildMember and not an APIInteractionGuildMember
For broader context, I'm writing a user context menu command to give the user a specific rolewhen not sent in a guild (server) there won't be any context to a guild - should be quite intuitive
:method: BaseInteraction#inCachedGuild()
discord.js@14.19.3
Indicates whether this interaction is received from a cached guild.Ah gotcha, I saw that function earlier but wasn't sure what options it narrowed the interaction to. I'll take a closer look now
if you deploy your command with just the guild context, you shouldn't ever receive one where this is an issue
but the library won't know about what you deployed + safeguarding against unexpected cases might in general be a good idea
so if that's false, just return / handle the case gracefully
Great okay, appreciate the help. I didn't realize that the interaction cache type was specifically for guild caching based on the naming scheme
understandable, cachetype is a broader concept in djs with quite some nuance to it
hence why we provide these utilities so you can (for the most part) ignore it and just use the higher abstraction layer to make sure your expectations are met
-# main use is type safe declaration of things