You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When handling an interaction, if I narrow the type using Interaction.inGuild(), the type is narrowed to one such that further calls to Interaction.inRawGuild() or Interaction.inCachedGuild() will end up with the type never.
My naive fix suggestion is to simply change the return type of Interaction.inGuild() from this is Interaction<'present'> to this is Interaction<'cached' | 'raw'>. This would fix my issue, but I don't know what the implications of this change are.
Hopefully I haven't misunderstood that inGuild() and inCachedGuild() are not mutually exclusive.
As a side note: 'present' is a bit weird of a name, I'm guessing that it means that it exists?
Code sample
import{CommandInteraction}from"discord.js";consthandleAsync=async(i: CommandInteraction)=>{if(!i.inGuild()){return;}// i is now CommandInteraction<"present"> & CommandInteraction<CacheType>if(i.inRawGuild()){// i is neverreturn;}if(i.inCachedGuild()){// i is neverreturn;}}
discord.js version
13.4.0
Node.js version
16.13.1
Operating system
WSL 2.0 on Windows 11
Priority this issue should have
Low (slightly annoying)
Which partials do you have configured?
No Partials
Which gateway intents are you subscribing to?
GUILDS
I have tested this issue on a development release
No response
The text was updated successfully, but these errors were encountered:
Actually, the only solution would be to use this is Interaction<'cached' | 'raw'> but this seems to bring another issue: guildId is Snowflake | null instead of Snowflake when using inGuild()
Reverting that fixes the Snowflake | null for me. But obviously that would also reintroduce the bug that it originally fixed. I would need a little more insight into this 'present' cache type. If it can be safely be represented by 'cache' | 'raw', then that will also work, this is definitely not easy to change without breaking types for anyone using CacheTypeReducer in their code.
Issue description
When handling an interaction, if I narrow the type using
Interaction.inGuild()
, the type is narrowed to one such that further calls toInteraction.inRawGuild()
orInteraction.inCachedGuild()
will end up with the typenever
.My naive fix suggestion is to simply change the return type of
Interaction.inGuild()
fromthis is Interaction<'present'>
tothis is Interaction<'cached' | 'raw'>
. This would fix my issue, but I don't know what the implications of this change are.Hopefully I haven't misunderstood that
inGuild()
andinCachedGuild()
are not mutually exclusive.As a side note: 'present' is a bit weird of a name, I'm guessing that it means that it exists?
Code sample
discord.js version
13.4.0
Node.js version
16.13.1
Operating system
WSL 2.0 on Windows 11
Priority this issue should have
Low (slightly annoying)
Which partials do you have configured?
No Partials
Which gateway intents are you subscribing to?
GUILDS
I have tested this issue on a development release
No response
The text was updated successfully, but these errors were encountered: