Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

666
Visualizações
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.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

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));

    }
about 4 years ago · Juan Pablo Isaza Relatório

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));
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda