Is there a way to make global app commands (/) only work via DMs?

I know how to prevent global commands from showing up in DMs but I'm wanting the other way around.
13 Replies
d.js toolkit
d.js toolkit12mo ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
Squid
Squid12mo ago
No, it's not possible You would have to deploy them globally, then manually return if the channel is not DM-based
Erin
Erin12mo ago
Alright ty If I wanted to exclude 2 commands from only being able to run via DMs (meaning they can be ran in a guild) this would be the correct code, right?
if (dmCommand.commandName != 'invite' && dmCommand.commandName != 'ping' && dmCommand) return interaction.reply('This command can only be ran in DMs.');
if (dmCommand.commandName != 'invite' && dmCommand.commandName != 'ping' && dmCommand) return interaction.reply('This command can only be ran in DMs.');
Cause it is not working. I tried running /ping and it is still saying that the command can only be ran via DMs. These would be the only 2 commands.
monbrey
monbrey12mo ago
Isnt dmCommand always going to be truthy
Erin
Erin12mo ago
I removed that and attempted again and same thing.
monbrey
monbrey12mo ago
So what is dmCommand here?
Erin
Erin12mo ago
That is all of my slash commands that I only want to be run in DMs
monbrey
monbrey12mo ago
So its an array?
Erin
Erin12mo ago
Yes ping me whenever someone has an idea. thanks in advance.
monbrey
monbrey12mo ago
Well arrays don't have properties like that. I'm not sure what you're attempting anymore. Would need to see far more surrounding code for context @dudethatserin
Erin
Erin12mo ago
I’m trying to make it so only the ping and invite commands can be used in guilds where other global application commands can only be used in DMs. https://github.com/DudeThatsErin/Omnivore-Bot/blob/main/index.js this is my entire index.js file. Bot is going to be open source.
monbrey
monbrey12mo ago
I'd just check interaction.commandName And if it's one of those two, let it be used
Erin
Erin12mo ago
Alright I’ll try that