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

165
Visualizações
Getting "Missing Access" error in console

I'm working on an add role command in discord.js v13 and this is the error I am getting: Error

const { MessageEmbed } = require("discord.js");
const Discord = require("discord.js")
const config = require("../../botconfig/config.json");
const ee = require("../../botconfig/embed.json");
const settings = require("../../botconfig/settings.json");

module.exports = {
  name: "addrole",
  category: "Utility",
  permissions: ["MANAGE_ROLES"],
  aliases: ["stl"],
  cooldown: 5,
  usage: "addrole <user> <role>",
  description: "Add a role to a member",

  run: async (client, message, args, plusArgs, cmdUser, text, prefix) => {

    /**
     * @param {Message} message
    */

    if (!message.member.permissions.has("MANAGE_ROLES")) return message.channel.send("<a:mark_rejected:975425274487398480> **You are not allowed to use this command. You need `Manage Roles` permission to use the command.**")

    const target = message.mentions.members.first();
    if (!target) return message.channel.send(`<a:mark_rejected:975425274487398480> No member specified`);
    const role = message.mentions.roles.first();
    if (!role) return message.channel.send(`<a:mark_rejected:975425274487398480> No role specified`);

    await target.roles.add(role)
    message.channel.send(`<a:mark_accept:975425276521644102> ${target.user.username} has obtined a role`).catch(err => {
      message.channel.send(`<a:mark_rejected:975425274487398480> I do not have access to this role`)
    })
  }
}

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

0

What your error means is that your bot doesn't have permissions to give a role to a user. It might be trying to add a role which has a higher position than the bot's own role. One way to stop the error is to give the bot the highest position. The bot will also require the MANAGE_ROLES permission in the Discord Developers page to successfully add roles in the first place. If you want to learn more about role permissions, I suggest you go here => Roles and Permissions. Also, when you are using .catch() at the end, all it is checking for is if the message.channel.send() at the end worked and if not, then send a message to channel telling that the bot was not able to add the role. Instead you need to use .then() after adding the role and then use .catch() to catch the error. Then, your code might look like this:

target.roles.add(role).then(member => {
    message.channel.send(`<a:mark_accept:975425276521644102> ${target.user.username} has obtined a role`)
}).catch(err => {
    message.channel.send(`<a:mark_rejected:975425274487398480> I do not have access to this role`)
})
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