#DiscordAPIError[50001] Missing Access | When adding a ROLE | Even though permissions are correct

341 messages · Page 1 of 1 (latest)

proper axle
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

faint totem
gritty hawk
#

Could it be because you're trying to add the role to every member in the guild and some members could be above the bot? Wait no, i read it wrong. But why don't you just do interaction.member.addRole()?

rare dune
#

doesnt GuildMemberManager.addRole take a guildmemberresolvable rather than a user?

covert grail
faint totem
#

This is functioning correctly on 10 other servers

rare dune
faint totem
#

Its just this one particular server where it's not working.

#

I thought it was to do with role hierarchy

covert grail
#

The bots own role needs to be above the role you are giving

rare dune
#

are u trying to addroles to someone a higher position than the bot on the server list

faint totem
#

so I had the server admin move the role of my bot to the top of the list

covert grail
#

Can’t give it to the owner of the server I don’t believe

gritty hawk
faint totem
#

this is where the bot sits in the roles list of the server

#

It's above all other roles

gritty hawk
#

And that role has permission to manage roles / administrator?

rare dune
#

is ur bot an admin 🐌

faint totem
#

Most notably the "Administrator" role

rare dune
#

are the roles u are trying to add in the guild

faint totem
#

It would be impossble for them to not be.

#

My dashboard gets a list of roles from the guild

#

Also the variable for roles is poorly named it infact is only giving one snowflake, not many.

gritty hawk
#

How many members does the other servers have? Approx.

faint totem
#

the other servers have less than 500 members combined.

#

this server has a few thousand

#

Bot is not verified

gritty hawk
#

Yeah maybe that could be the issue when you're getting the members

#

Can you try interaction.member.addRole?

rare dune
#

i dont see why that would occur, but u can try using the guildmemberrolemanager or the guildmembermanager

faint totem
#

Typescript is telling me that interaction.member.addRole isn't a property

rare dune
#

or use member.roles.add

faint totem
#

addRole is only on Guild.members, correct?

gritty hawk
rare dune
gritty hawk
#

Looks like it takes users too. .add only takes member

faint totem
#

intillisense isn't happy about .add

#

Property 'add' does not exist on type 'GuildMemberRoleManager | string[]'

rare dune
#

it most definetely does, its a method btw

faint totem
#

Oh I see it in the documentation

#

but the types claim it doesn't lol

gritty hawk
faint totem
#

Guess I need to typecast to guildmemberrolemanager

rare dune
#

ts moment

faint totem
#

my entire life if a ts moment.

rare dune
faint totem
#

can I pass the snowflake or do I have to do a lookup for the role and pass a role to roleOrRoles?

gritty hawk
faint totem
#

pushing to aws, ill let you all know

#

Still the same error

#

Ill have them kick the bot again

#

blow away my db for their guild

gritty hawk
#

What does your code look like?

rare dune
#

can u log the role obj ur trying to add

faint totem
#

the member I am trying to add the role to is myself

#

the role I am trying to is the correct ID

rare dune
#

and ur in the server of course right

faint totem
#

the guild is the correct guild

#

yes

#

its a slash command

gritty hawk
#

Can you show the code?

#

And try and log the role obj like vunsh asked :)

faint totem
#

so I run /verify parameter from the server and use the interaction object to attempt to add the role

rare dune
#

oh its a verify cmd

#

does the bot have access to a verify channel, presumably the one u have access to right now

faint totem
#

yeah

#

wait

#

I technically lied

#

let me verify

#

;p;

rare dune
#

it has admin so technically it should but good to make sure

faint totem
#

It does have access to the channel., yes

#

the interaction comes through

#

there are a lot of gates that have to be passed before this moment

#

including database lookups for product information

#

those all work

rare dune
#

i think the most likely issue is that the role is somehow not a role in that server

gritty hawk
#

I don't think you can get the members with interaction.guild?.members when it has that many members. I could be wrong though, but I'm pretty sure you can't

faint totem
#

someone mentioned it might have to do with the number of members of guild

rare dune
#

is roleids an array, or a single role

faint totem
#

single role snowflake

#

as string

gritty hawk
#

So just a role ID?

faint totem
#

correct

gritty hawk
#

Does that even work?

rare dune
#

yea it does

gritty hawk
#

Didn't know that.

#

But since you changed the code, I'm assuming you're getting a different error than before or?

faint totem
#

no the exact same error

#

I can have the server owner kick the bot again

gritty hawk
#

I doubt that'd fix the issue

faint totem
#

Im not entirely sure how the discord permissions would look correct

rare dune
#

and log it

faint totem
#

is this something I can new up

gritty hawk
#

As long as the bot is above the member it tries to add a role to, it should be fine.

faint totem
#

or does it hang off another property somewherE

#

oh its on my client

rare dune
#

yea

faint totem
#

maybe I should just try to use the client to do this instead of the interaction?

rare dune
#

nah that wont make a difference

#

accessing the same things

faint totem
gritty hawk
#

My guess would be interaction.guild.roles.cache.get(roleID)

rare dune
#

^

faint totem
#

the above returns [CLIENT-BOT] | Role: <@&981266467976781905> | 10/10/2022, 7:37:44 PM

#

well

#

&981266467976781905

gritty hawk
#

That's not a role ID

#

Try again, but remove the &

faint totem
#

specifically returns <@&981266467976781905 >

rare dune
#

and 981266467976781905 matches the id of the role ur attempting to add?

faint totem
#

yes

gritty hawk
#

Alright, so the role exists and the bot is above that role, right?

faint totem
#

yes

rare dune
#

can u log all the clients permissions? sorry for the random requests im just confused on this

faint totem
#

I called that out above, that I checked that the role of the bot was above all other roles in the server.

rare dune
#

interaction.guild.members.me.permissions

faint totem
#

oh good idea

#

PermissionsBitField { bitfield: 987640626271n }

#

ill go look at what those are now

rare dune
# faint totem ill go look at what those are now
Permission deconstruction for 987640626271:
[✔] CreateInstantInvite (1) 1<<0
[✔] KickMembers (2) 1<<1
[✔] BanMembers (4) 1<<2
[✔] Administrator (8) 1<<3
[✔] ManageChannels (16) 1<<4
[✔] ManageGuild (32) 1<<5
[✔] AddReactions (64) 1<<6
[✔] ViewAuditLog (128) 1<<7
[✔] PrioritySpeaker (256) 1<<8
[✔] Stream (512) 1<<9
[✔] ViewChannel (1024) 1<<10
[✔] SendMessages (2048) 1<<11
[✔] SendTTSMessages (4096) 1<<12
[✔] ManageMessages (8192) 1<<13
[✔] EmbedLinks (16384) 1<<14
[✔] AttachFiles (32768) 1<<15
[✔] ReadMessageHistory (65536) 1<<16
[✔] MentionEveryone (131072) 1<<17
[✔] UseExternalEmojis (262144) 1<<18
[✔] ViewGuildInsights (524288) 1<<19
[✔] Connect (1048576) 1<<20
[✔] Speak (2097152) 1<<21
[✔] MuteMembers (4194304) 1<<22
[✔] DeafenMembers (8388608) 1<<23
[✔] MoveMembers (16777216) 1<<24
[✔] UseVAD (33554432) 1<<25
[✔] ChangeNickname (67108864) 1<<26
[✔] ManageNicknames (134217728) 1<<27
[✔] ManageRoles (268435456) 1<<28
[✔] ManageWebhooks (536870912) 1<<29
[✔] ManageEmojisAndStickers (1073741824) 1<<30
[✔] UseApplicationCommands (2147483648) 1<<31
[✔] RequestToSpeak (4294967296) 1<<32
[✔] ManageEvents (8589934592) 1<<33
[✔] ManageThreads (17179869184) 1<<34
[✔] CreatePublicThreads (34359738368) 1<<35
[✔] CreatePrivateThreads (68719476736) 1<<36
[✔] UseExternalStickers (137438953472) 1<<37
[✔] SendMessagesInThreads (274877906944) 1<<38
[✔] UseEmbeddedActivities (549755813888) 1<<39
[✔] ModerateMembers (1099511627776) 1<<40
#

manage roles and admin, so looks like thats good

faint totem
#

youll have to teach me your deconstruction trick later, thanks.

#

Im pretty lost

#

The bot has the permissions, the bot has the interaction, the interactions work, adding the role fails due to a missing access

#

what other access could the bot need

rare dune
faint totem
#

very nice, great info

rare dune
gritty hawk
#

The only thing I can come up with is the role not being an actual role at this point

faint totem
rare dune
faint totem
#

^

gritty hawk
faint totem
#

thats my output

#

for my bot

#

I wrote a helper function

gritty hawk
#

Can you show the exact code where you're getting and logging it

faint totem
#

its just a simple little log tool so I can quickly see where in my bot things are broken

#

so for the thing you copied I had this
consoleLogMessageWithType(`Role: ${interaction.guild?.roles.cache.get(roleIds)}`, 'client-bot')

#

where ${interaction.guild?.roles.cache.get(roleIds)} resolved into a role.

gritty hawk
#

Can you try ```js
let role = interaction.guild.roles.cache.get('roleID')
console.log(role)

faint totem
gritty hawk
faint totem
#

I don't understand the difference between returning the role as a template literal and returning the role as a direct reference

#

They will be the same value regardless, right?

lofty kindle
#

really you could just do

export const consoleLogMessageWithType = (message: string, type: string) => {
    console.log(`[${type.toUpperCase()}] | ${message} | ${new Date().toLocaleString()}`);
}
rare dune
gritty hawk
#

^

faint totem
lofty kindle
faint totem
rare dune
#

name: 'Oceanology 5'
is that the correct guild?

faint totem
#

yes

#

I have a BOT an API and a Dashboard.

#

all of which I custom coded over the last two months

#

This particular function works fine in my other servers.

rare dune
#

is the role attempting to be added an administrator role

faint totem
#

let me verify

rare dune
#

doesnt look like it from the perm bitfield but j in case

faint totem
#

it shouldn't be but I am awaiting reponse from the guild owner now.

#

I really, really, really, wish this was just ignorance and IDs were wrong.

#

but it seems to be something else entirely

rare dune
#

looks like thats out of the question now

#

im convinced thsi is some obscure api error

gritty hawk
#

I have to ask - you 1) saved the code and 2) restarted the bot after, right?

faint totem
#

yes

#

ill try to not get offended.

gritty hawk
#

And you did try to readd the bot too right?

faint totem
gritty hawk
#

Re-add

faint totem
#

The bots been kicked and re-added about 5 times

#

but not recently.

#

my databases have also been dropped

#

when kicking the bot

#

is there a way to check if I am ratelimited from adding roles to users in a specific guild/bucket?

rare dune
#

dont believe so, but that error would not be thrown upon a rate limit

#

can u try adding a random other role in that guild by its id in uir code?

faint totem
#

Im trying to think out of the box at this point lol

rare dune
#

like instead of supplying roleIds supply some other role id in a string

faint totem
#

let me try to call the api end point directly

gritty hawk
faint totem
#

and see if that errors out

#

The only difference between the two is typescript syntax

#

if I do the above typescript will not let me compile

#

as roles is string as well and add doesn't exist on string.

gritty hawk
#

Ahh oka, I don't use typescript so I wouldn't know xd

rare dune
#

yea it forces u to cast it right

rare dune
faint totem
#

fwiw

gritty hawk
#

Hmm, maybe the role isn't cached 👀 i have no idea at this point, but can you try and add it with the role obj instead of it's id?

faint totem
#

I tried with the role object

rare dune
#

if it wasnt cached it wouldnt be able to be gotten via cache.get

faint totem
#

headed to postman to try and put the endpoint

#

yeah post man says the same

#

{
"message": "Missing Access",
"code": 50001
}

rare dune
#

try using a different role

faint totem
#

Same

#

any role

#

on this discord

gritty hawk
#

Looking at other issues, regenerating your bot's token is a possible fix?

faint totem
#

I have a CI/CD that regenerates my token on every release

#

which is how ive been testing these changes

#

so its safe to say ive done that

gritty hawk
#

Which intents do you have enabled? Both on the D dev portal and in your code

faint totem
#
const client = new DiscordClient({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.GuildMembers,
    GatewayIntentBits.MessageContent,
    GatewayIntentBits.GuildIntegrations
  ],
});
zealous orbit
#

ok so I just entered here and was at the top
And had to scroll down dogeHaHa

faint totem
#

youve got a good 200+ messages to read up ill drop the tldr
bot is joined in a guild with the correct permissions but is unable to add a role to a member, even though the bots role is at the top of the roles list.

zealous orbit
#

why are you unable

#

Missing Permissions error as in title?

gritty hawk
#

Missing Access

zealous orbit
#

the bot isn't in the guild ig

faint totem
#

should I move this over to the official discord?

gritty hawk
#

Have asked several times xd

zealous orbit
#

ok I'm out
too much missing context

rare dune
#

bot is there bot is highest role bot has admin role isn’t admin role is an actual role ids match role is in guild

#

no idea what else to test

gritty hawk
#

Which permissions are you adding the bot with?

faint totem
#

For the most recent the guild owner checked every permission possible.

gritty hawk
#

What about its scopes

#

Do you have these: scope=bot%20applications.commands ?

faint totem
#

yes

zealous orbit
#

can you show the full error

faint totem
faint totem
zealous orbit
#

oh

faint totem
#

I also tried in postman

#

same error

#

{
"message": "Missing Access",
"code": 50001
}

#

only thing I can think is that I am ratelimited?

#

but I wasn't aware you could get ratelimited adding a permission from a cache.

gritty hawk
#

You wouldn't get that error from ratelimits though

faint totem
#

yeah I figured I wouldn't but it was worth the sanity check

gritty hawk
#

True. Are you sure about where it breaks btw?

faint totem
#

yea

#

its breaking in a .catch() on the add for a role

#

and calling the API directly from postman results in the same error message

gritty hawk
#

Can you maybe resend the code in a codeblock so it's easier to see

faint totem
#

Is this possibly because my bot isn't verified and its in a very large server

rare dune
#

no

rare dune
#

my only theory now is that the role is a role that belongs to a different guild even tho from what u provided it isn’t

faint totem
#

whats the endpoint to get roles from a guild

#

ill call it via postman.

gritty hawk
#

The command is being used in the same guild as the role is in ye?

faint totem
#

okay

#

now this is interesting

#

{
"id": "1029141478418686045",
"name": "Marketplace Role Manager",
"permissions": "296150887519",
"position": 7,
"color": 0,
"hoist": false,
"managed": true,
"mentionable": false,
"icon": null,
"unicode_emoji": null,
"flags": 0,
"tags": {
"bot_id": "1015736903871508600"
}
}

#

its position from the api is lower

rare dune
#

maybe the api isn’t recognizing that ur bots in the server for whatever reason

zealous orbit
rare dune
#

not the one he’s trying to add

faint totem
zealous orbit
#

wai

#

ok

faint totem
#

should I move over to discord and ask there?

rare dune
#

like the admin role

faint totem
#

I can ask the server owner too

#

It didn't help

rare dune
#

try this

zealous orbit
#

you're using the right token, right?

rare dune
#

<guild>.roles.setPosition(roleIds, 7)

faint totem
#

Before I move the role of a server with thousands of users with a guild owner I don't have a strong relationship with for a bot I just recently started advertising for, what will happen after changing the roles position?

gritty hawk
#

The role will just get a different position in the roles section

faint totem
rare dune
gritty hawk
#

Although, I don't think it's smart to move that role above the Admin role

#

Wait, now I'm confused.

rare dune
#

the only reason i suggest it is because for whatever reason its not getting position value correctly

gritty hawk
#

Isn't the lowest role's position 1 ?

#

So setting the role they are trying to give to 7, would place it above the Admin role, which might now be the smartest move in a larger server.

faint totem
#

I had the server owner resave the Marketplace role

#

{
"id": "1029141478418686045",
"name": "Marketplace Role Manager",
"permissions": "296150887519",
"position": 1,
"color": 0,
"hoist": false,
"managed": true,
"mentionable": false,
"icon": null,
"unicode_emoji": null,
"flags": 0,
"tags": {
"bot_id": "1015736903871508600"
}
}

#

its now at position 1

#

still the same error

rare dune
faint totem
#

DiscordAPIError[50001] Missing Access | When adding a ROLE | Even though permissions are correct

#

{
"id": "981266467976781905",
"name": "OCEANOLOGY",
"permissions": "1071594724417",
"position": 2,
"color": 3447003,
"hoist": false,
"managed": false,
"mentionable": true,
"icon": null,
"unicode_emoji": null,
"flags": 0
},

#

its position os 2

gritty hawk
#

Makes sense looking at this image

#

The bot's role's position should be 7, not 1

#

Position 1 is the lowest role.

faint totem
#

position 1 is the lowest?

gritty hawk
#

Yes.

#

Position 7 is the highest in that server

rare dune
#

did not know that, thank u mazikeen

gritty hawk
#

So yeah it looks like the API quite isn't following 🤷‍♀️

faint totem
#

so you are saying the positions should go like that?

gritty hawk
#

everyone is 0

faint totem
#

and not the other way around?

#

oh I see

rare dune
#

well no ur bot is where its supposed to be

#

but for whatever reason the api thinks otherwise

faint totem
#

it was at position 7 earlier

#

when I had this problem

gritty hawk
#

Not according to the API since it says position 1

faint totem
#

but now it's saying 1

rare dune
#

and when the owner gave the bot the admin role it still didnt work ?

faint totem
#

correct

gritty hawk
#

Can you send a new image of the roles and log the bot's role once again?

faint totem
#

just asked the server owner to do so

gritty hawk
#

Yeah, which is even more confusing. But it is at 1 right now?

faint totem
#

yeah

#

1 right this second

#

waiting for the owner to change the position

gritty hawk
#

If it is at 1 in the roles section aswell, try changing it's position to e.g. 3, save, and back to 7

zealous orbit
#

did I miss something
because if the problem is role positions, the error should be Missing Permissions

faint totem
#

moved it to 2

#

then moved it to 6

#

it now works

#

and permissions are added

gritty hawk
#

Great

rare dune
#

well better late than never

gritty hawk
#

Glad it worked out so quickly xd

faint totem
#

How do I after action this lol.

zealous orbit
#

what

faint totem
#

How do I describe why this happened; when the position were originally correct and it was not working.

gritty hawk
#

Discord's API just being Discord's API. 😄

faint totem
#

I guess the solution if this happens to other customers in the future would be to move the position multiple times?

rare dune
#

yeah, shuffle them around then set them back

faint totem
#

Thank you everyone for walking through this with me and helping me troubleshoot this not so obvious error.

rare dune
#

though this shouldnt reoccur i hope

gritty hawk
spring yarrow
mental frigate
#

nope