Type-safety for guild-only slash commands
I understand that
ChatInputCommandInteraction#guildId
is nullable, but is there some sort of way to assert it's going to be run in a guild? I'm setting .setDMPermission(false)
on the builder, do I need to .guildId!
everywhere or is there a better method?26 Replies
Solution
https://github.com/discordjs/discord.js/blob/a76c1ddacc5eb80adbf0a70756f451d709b1a000/packages/discord.js/src/structures/BaseInteraction.js#L178-L180
If you really dont want that, then type it with the same type that
inGuild
makes it: https://github.com/discordjs/discord.js/blob/a76c1ddacc5eb80adbf0a70756f451d709b1a000/packages/discord.js/typings/index.d.ts#L1100Thanks!
How about guild
Is there any options for it
by using
inGuild
?
interaction.inGuild
literally what I said
oh
Idk what the error is broI have check it but not working
TS probably doesnt propegate it into the for loop
Somehow only work with guildId
if you do
const { channels } = interaction.guild
above the for loop it probably worksThat good Idea
Thanks
Working now
Oh check it but still not work
Just that line not error
that's not what I said
you have to grab channels
I don't see different behaviour frome 2 line of code but anyway it still not work
use
inCachedGuild
FYI like the original question this is not strictly sapphire related
this is all pure DJS
Sorry
I just search arround and find this question
Above solution work with me
it's alright
just yaknow be sure it is cached
it would normally always be
unless you set up aggressive cache sweepers yourself
Noted
My original question was Framework-related because it was about "does
Command
have a safety/subclass for this"Or
InteractionType<'cached'>
Not my question, this is unrelated
I was even talking to you?
And yes, Is related
This is not related to Sapphire nor to the question asked
I'm OP...