I'm writing a Discord bot using TypeScript and Discord.js to implement a game.
As part of the game, I would like certain commands to be secret - they should be restricted to one user only, and the user should not have a role to indicate they have access to this command. I cannot find anything in the guide or the docs about how to accomplish this, or if it is possible.
Here is an example slash command, which is visible only to admins. This works, but I do not know how to make it work for only a specific user.
{
data: new SlashCommandBuilder()
.setName("protect")
.setDescription("Protect a user from all visits")
.setDefaultMemberPermissions(0)
.addUserOption(
(option): SlashCommandUserOption =>
option.setName("target").setDescription("The user you wish to protect").setRequired(true),
),
async execute(interaction: ChatInputCommandInteraction) {
const target = interaction.options.getUser("target");
await interaction.reply(`You have selected ${target?.username}!`);
},
}
Turns out there is a way to do this using the Discord app itself.
.setDefaultMemberPermissions(0)
to its data
property, e.g.{
data: new SlashCommandBuilder()
.setName("protect")
.setDescription("Protect a user from all visits")
.setDefaultMemberPermissions(0)
),
async execute(interaction: ChatInputCommandInteraction) {
// action execution code...
},
}
I do not believe there is a way to do this in a programmatic manner using Discord.js, but this option fits my use case.