Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

215
Vistas
Channel permissionOverwrites is working perfectly in 90% of the guilds but in some guilds its returning error

So as I said in the title in some guilds the channel permissionOverwrites is not working which leads to crashing the bot.

Here's the code:

const qu = message.guild.roles.cache.find(
  (role) => role.name.toLowerCase() === '',
);
if (!qu) {
  try {
    let qu = await message.guild.roles.create({
      name: '',
      color: '#',
    });
    try {
      await message.guild.channels.cache.forEach(async (channel) => {
        await channel.permissionOverwrites
          .edit(qu, {
            VIEW_CHANNEL: false,
          })
          .then(console.log)
          .catch(console.error);
      });
    } catch (e) {
      await console.log(e);
    }
  } catch (e) {
    await console.log(e);
  }
}

Here's the error I get on the console:

TypeError: Cannot read properties of undefined (reading 'edit')

channel.permissionOverwrites.edit, .create and .set returns same error. I don't know what's behind this error, if you got any idea why please let me know.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Not every channel has permissionOverwrites. ThreadChannels, and DirectoryChannels for example don't have them. If a guild has these channels cached, you will receive an error in your forEach loop. I'd log and check channel.type to see which types cause these errors.

To solve this, you either need to filter these out:

await message.guild.channels.cache
  .filter(
    (channel) =>
      ![
        'GUILD_DIRECTORY',
        'GUILD_NEWS_THREAD',
        'GUILD_PRIVATE_THREAD',
        'GUILD_PUBLIC_THREAD',
      ].includes(channel.type),
  )
  .forEach(async (channel) => {
    await channel.permissionOverwrites
      .edit(qu, {
        VIEW_CHANNEL: false,
      })
      .then(console.log)
      .catch(console.error);
  });

... or only include the ones you need (e.g. TextChannel, and CategoryChannel):

await message.guild.channels.cache
  .filter((channel) =>
    [
      'GUILD_CATEGORY',
      'GUILD_TEXT',
      'GUILD_VOICE',
    ].includes(channel.type),
  )
  .forEach(async (channel) => {
    await channel.permissionOverwrites
      .edit(qu, {
        VIEW_CHANNEL: false,
      })
      .then(console.log)
      .catch(console.error);
  });
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda