1

I made a lock command for my bot which runs on a framework called, discord.js-commando. This command locks a channel by not letting users send messages. The error is at line if(perms.deny.has('SEND_MESSAGES'). The error is Cannot read property 'deny' of undefined.

  • MY CODE
async run(msg, args){
           // For Text Channel
           if(args.channel.type === 'text'){

               const perms = args.channel.permissionOverwrites.get(msg.guild.id);

               if(perms.deny.has(`SEND_MESSAGES`)){
                   return msg.reply(
                       new MessageEmbed()
                       .setDescription(`⚠️ | Channel is already locked`)
                       .setColor('BLUE')
                   )
               } else {

               args.channel.updateOverwrite(msg.guild.roles.everyone, {
                   SEND_MESSAGES: false
               }).catch(err => {
                   return msg.channel.send(new MessageEmbed()
                       .setDescription(`<:xmarkxl:870951478913806396> | Failed to lock channel, \`${err}\``)
                       .setColor('RED')
                   )
               })
               
               await msg.channel.send(
                   new MessageEmbed()
                   .setDescription(`<:checkmarkxl:870951478829936710> | Successfully Locked <#${args.channel.id}>`)
                   .setColor("GREEN")
                   )
               }

           } 
   

I want to know if there's an easy way to check if @everyone have permission to send messages in the channel to lock.

Darshan B
  • 658
  • 1
  • 5
  • 19
  • 2
    What are you trying to accomplish by `args.channel.permissionOverwrites.get(msg.guild.id)`? It is clearly returning `undefined`. You shouldn't pass guild ID there, according to [docs](https://discord.js.org/#/docs/main/stable/class/PermissionOverwrites?scrollTo=id), it accepts either user ID or role ID. – Skulaurun Mrusal Aug 05 '21 at 11:23
  • what is args in your case ? .Why it not `msg.channel.permissionOverwrites.get()` – HellCatVN Aug 05 '21 at 20:00
  • I'm using commando, so I specify args under `super(client)` and I destructure it as `args.channel` – Darshan B Aug 06 '21 at 06:01

0 Answers0