• Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Precios
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

129
Vistas
How to fix TypeError [INVALID_TYPE]: Supplied parameter is not a User nor a Role

I'm running into a problem when I'm trying to create a role and a text channel. The role created will set permissions for the text channel.

if (id === '4') {
  message.guild.roles.create({
    name: `Owner`,
    color: `${color.white}`,
    permissions: ['ADD_REACTIONS'],
    hoist: true,
  });

  let owner = message.guild.roles.cache.find((role) => role.name === 'Owner');

  name = `${names.name}`,
    message.guild.channels
      .create(name, {
        type: 'GUILD_TEXT',
        permissionOverwrites: [
          {
            id: owner,
            allow: ['ADD_REACTIONS'],
            deny: ['VIEW_CHANNEL'],
          },
        ],
      })
      .catch((err) => console.log(err));
}

Although it creates the role, when it comes to the text channel, it cannot find the role made and throws an error:

TypeError [INVALID_TYPE]: Supplied parameter is not a User nor a Role.

I'm unsure how to fix this.

9 months ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

It looks like you haven't awaited the role create a function. Try using this code:

 if(id === '4'){


        await message.guild.roles.create({
            name: `Owner`,
            color: `${color.white}`,
            permissions: ["ADD_REACTIONS"],
            hoist: true
        });


        let owner = message.guild.roles.cache.find(role => role.name === "Owner");

        name = `${names.name}`,
        await message.guild.channels.create(name, {
            type: "GUILD_TEXT",  
            permissionOverwrites: [{
                id: owner,
                allow: ['ADD_REACTIONS'],
                deny: ['VIEW_CHANNEL']
            }]
        }).catch(err => console.log(err));

    }
9 months ago · Juan Pablo Isaza Denunciar

0

roles.create() is an asynchronous method, which means it returns a promise and allows the rest of your code to run without blocking anything. It also means that when you try to find the newly created role on the next line, it won't be there as it's not even created, so it will be undefined. As undefined is not a valid Role or User, you receive a TypeError.

However, roles.create() resolves to the newly created role, so you can wait for it to be created (using await for example) and grab its value. This way you don't even need to find it later. Check out the code below:

let owner = await message.guild.roles.create({
  name: `Owner`,
  color: color.white,
  permissions: ['ADD_REACTIONS'],
  hoist: true,
});

message.guild.channels
  .create(names.name, {
    type: 'GUILD_TEXT',
    permissionOverwrites: [
      {
        // now owner is a valid role
        id: owner,
        allow: ['ADD_REACTIONS'],
        deny: ['VIEW_CHANNEL'],
      },
    ],
  })
  .catch((err) => console.log(err));
9 months 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 empleo Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.