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}!`);
},
}
Liam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.