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

183
Vistas
discord.js - Cannot read property 'roles' of undefined

I want to try to fix this error, but I have no clue on how the code im using:


const rainPerms = [
    "MANAGE_ROLES",
    "ADMINISTRATOR"
  ];

    let place = 0;
    const servers = ["111111111111111111", "222222222222222222"] //fake ID
    const Guilds = client.guilds.cache.map(guild => guild.id);
    const Server = Guilds
    function changeColor() {
        for (let index = 0; index < servers.length; ++index) {
            let server = client.guilds.cache.get(servers[index]);
            let role = server.roles.cache.find(r => r.name === 'Rainbow');
            role.setColor(rainbow[place]).catch;
            if (!rainPerms) {
            }
            continue;
            }
        }
        if (place == (size - 1)) {
            place = 0;
        } else {
            place++;
        }
    client.on('ready', () => {
        setInterval(changeColor, 60000);
        changeColor();
    });

and my error is:

let role = server.roles.cache.find(r => r.name === 'Rainbow');
                  ^
                    
TypeError: Cannot read property 'roles' of undefined

I have searched all over and I could not find much that I could understand, could someone please explain what exactly is going on here? thanks!

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

0

I would not recommend using roles cache if you're using v12/v13, instead use an async function.

To get guild:

let guild = await client.guilds.fetch('id')

And to get a role:

let role = await guild.roles.fetch('id')
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