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

277
Views
channel permissions overwrites not working despite bot saying it works, discord.js

I am creating a slash command to overwrite permissions on a private text channel so that when the command is called, a channel and role is specified by the user and that role is the only one that will be able to see that channel. I am using the permission overwrite manager to accomplish this but when the command is run, it will say it worked but when I actually check the channel, nothing has changed. My code for this command is below. What am I doing wrong?

const { Permissions } = require('discord.js');

module.exports = {
    data: new SlashCommandBuilder()
    .setName('givechannel')
    .setDescription('Give an existing role to a channel')
    .addChannelOption((option) => 
        option
        .setName('target')
        .setDescription('Channel to give the role to')
    )
    .addRoleOption(option => 
        option
        .setName('role')
        .setDescription('role to give the channel')
    ),

    async execute(interaction) {
        const channel = interaction.options.getChannel("target");
        const role = interaction.options.getRole("role");
        const name = interaction.guild.channels.cache.get(channel.id);
        const id = interaction.guild.roles.cache.get(role.id);
                    
        if (!name) {
            interaction.reply({ content: `That channel does not exist in the server!`, ephemeral: true});
            return;
        }

        if (!id) {
            interaction.reply({ content: `That role does not exist in the server!`, ephemeral: true })
        }
            
        if (!interaction.member.permissions.has([Permissions.FLAGS.ADMINISTRATOR])) {
            interaction.reply({ content: `You don't have the permissions to give roles!`, ephemeral: true});
            return;
        } else {
            try {
                await interaction.channel.permissionOverwrites.edit( role, { VIEW_CHANNEL: true });
                interaction.reply({ content: `${channel} has been given ${role} role!`, ephemeral: true});
            } catch(err) {
                console.log(err)
                interaction.reply({ content: `Failed to give ${role} to ${channel}!`, ephemeral: true });
                return;
            }
        }
    }
}
about 4 years ago · Juan Pablo Isaza
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!