It works but still getting this error: UnhandledPromiseRejectionWarning: DiscordAPIError: Missing Permissions

那年仲夏 提交于 2021-02-11 17:58:38

问题


This error is a weird one because the code works: it creates an admin role with the Administrator flag. And most importantly: the bot is above the ADMIN role and is Administrator.

The error appears when it's creating the role. The error says it's missing permissions but the ADMIN role is created successfully so it didn't fail. And there's another thing: when I leave out the position parameter it works just fine, no errors at all. But unfortunately I need the position parameter because I want to add more roles. What am I missing here?

bot.on('ready', () => {
  const ids = bot.guilds.cache.map(guild => guild.id);

// Checks if the necessary roles are present on every guild, creates them if they are not there.
  for (const id of ids) {
    let guild = bot.guilds.cache.get(id);
    async function assignRoles() {
    let adminRole = guild.roles.cache.find(role => role.name === "ADMIN") ? console.log("Role ADMIN is present at " + '\x1b[36m%s\x1b[0m%s', guild.name, ".") : guild.roles.create({
      data:{
      name:"ADMIN",
      color:"GREEN",
      hoist: true,
      position: 2,
      permissions: ["ADMINISTRATOR"]
      },
    reason:"The administrator role.",
    }).then(console.log("Created the necessary role ADMIN at " + '\x1b[35m%s\x1b[0m%s', guild.name, "."))

    let allRole = await adminRole; // + await mutedRole + await friendRole
    return allRole;
    }
    assignRoles();

  } 
}

来源:https://stackoverflow.com/questions/64201709/it-works-but-still-getting-this-error-unhandledpromiserejectionwarning-discord

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!