Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
Get role id in slashcommand option

I'm trying to make a command where you can put a role inside an option. If the user mentions a role within the slashcommand option, this role becomes an ID to be later added to the channel to the channel to see the content.

If the user does not put any role, the permission is assigned in @everyone

I tried something like this as I've seen in some situations I've researched:

module.exports = {
  data: new SlashCommandBuilder()
    .setName("esconder")
    .setDescription("Comando para desativar a permissão de visualização nos chats.")
    .addStringOption(option => option.setName("cargo").setDescription("Informa uma quantidade de mensagens que queres apagar!")),

  async execute(interaction, client) {

  let cargo = " ";
  if (interaction.options._hoistedOptions[0]) {
    cargo = interaction.options._hoistedOptions[0].value;
  } else {
    cargo = "990039749362319380"; // Everyone ID
  }

  if (cargo) {
    const role2 = interaction.guild.roles.cache.find(role => role.name === cargo);

    const guild = client.guilds.cache.get(configGuids.servidores.principal);
    const role = guild.roles.cache.get(role2.id)

    interaction.channel.permissionOverwrites.edit(role, { VIEW_CHANNEL: true });
    return await interaction.editReply({ content: `Added ${cargo} to the channel` });
  }
  }
};

But it's not working as it should. Before I had put it to diction with the ID and it worked perfectly.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use addRoleOption instead.

You can get an option's value with this: interaction.options.getRole('name'). Parsing Options

module.exports = {
    data: new SlashCommandBuilder()
        .setName("esconder")
        .setDescription("Comando para desativar a permissão de visualização nos chats.")
        .addRoleOption(option => {
            option.setName("cargo")
                .setDescription("Informa uma quantidade de mensagens que queres apagar!")
                .setRequired(true)
            return option;
        }),

    async execute(interaction, client) {
        const cargo = interaction.options.getRole("cargo");

        interaction.channel.permissionOverwrites.edit(cargo.id, { VIEW_CHANNEL: true });
        return await interaction.reply({ content: `Added ${cargo.name} to the channel` });
    }
};
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!