Slash Commands
I'm having trouble restricting the slash commands so that they only appear on the servers where the bot is installed. They even appear in users' DMs.
Can you please help me?
Below is my command registration code:
14 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 OPspecify the context in the command payload
:discord: Application Commands - Create Global Application Command
POST /applications/\application.id/commands
Create a new global command. Returns 201
if a command with the same name does not already exist, or a 200
if it does (in which case the previous command will be overwritten). Both responses include an application command object.
read morecontexts
Thank you.
It worked correctly.
np, glad it worked
Another question please.
Do you know why the command below does not work when the user executes the slash command in DM?
"does not work" surfaces how?
does it reach that code?
When it runs in a server channel it works, but when it runs through DM it doesn't.
I'm using a translator and it might be a little difficult to understand.
does it reach that portion of code? (try putting a log there)
if not, there might be some part of your command handler like "in cached guild" guards that prevents execution
Now I understand your tip.
I think it's correct.
I will put the beginning of the code.
it should be a chat input command still, but it won't be in the context of a guild/cached guild if that's something you expect/enforce in code
:method: CommandInteraction#inCachedGuild()
[email protected]
Indicates whether this interaction is received from a cached guild.Thanks!