#DiscordAPIError[50001] Missing Access | When adding a ROLE | Even though permissions are correct
341 messages · Page 1 of 1 (latest)
exact error:
rawError: { message: 'Missing Access', code: 50001 },
code: 50001,
status: 403,
method: 'PUT',
url: 'https://discord.com/api/v10/guilds/G?UILDID/members/MEMBERID/roles/ROLEID',
requestBody: { files: undefined, json: undefined }
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()?
doesnt GuildMemberManager.addRole take a guildmemberresolvable rather than a user?
Also takes user resolvable
This is functioning correctly on 10 other servers
interesting
Its just this one particular server where it's not working.
I thought it was to do with role hierarchy
The bots own role needs to be above the role you are giving
are u trying to addroles to someone a higher position than the bot on the server list
so I had the server admin move the role of my bot to the top of the list
Can’t give it to the owner of the server I don’t believe
Is the bot above the member?
this is where the bot sits in the roles list of the server
It's above all other roles
And that role has permission to manage roles / administrator?
is ur bot an admin 🐌
Most notably the "Administrator" role
are the roles u are trying to add in the guild
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.
How many members does the other servers have? Approx.
the other servers have less than 500 members combined.
this server has a few thousand
Bot is not verified
Yeah maybe that could be the issue when you're getting the members
Can you try interaction.member.addRole?
i dont see why that would occur, but u can try using the guildmemberrolemanager or the guildmembermanager
Typescript is telling me that interaction.member.addRole isn't a property
addRole is only on Guild.members, correct?
Yeah was just about to say 🐌
oh didnt see the lack of members, yea try using <guildmember>.roles.add
https://discord.js.org/#/docs/discord.js/14.4.0/class/GuildMemberRoleManager?scrollTo=add u can still provide a reason so should be okay
Looks like it takes users too. .add only takes member
intillisense isn't happy about .add
Property 'add' does not exist on type 'GuildMemberRoleManager | string[]'
it most definetely does, its a method btw
Wdym?
Guess I need to typecast to guildmemberrolemanager
ts moment
my entire life if a ts moment.

can I pass the snowflake or do I have to do a lookup for the role and pass a role to roleOrRoles?
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
What does your code look like?
can u log the role obj ur trying to add
the member I am trying to add the role to is myself
the role I am trying to is the correct ID
and ur in the server of course right
so I run /verify parameter from the server and use the interaction object to attempt to add the role
oh its a verify cmd
does the bot have access to a verify channel, presumably the one u have access to right now
it has admin so technically it should but good to make sure
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
i think the most likely issue is that the role is somehow not a role in that server
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
yeah I am now doing this:
(interaction.member?.roles as GuildMemberRoleManager).add(
roleIds,
'Verified ownership of the product via automated slash command.'
)
someone mentioned it might have to do with the number of members of guild
is roleids an array, or a single role
So just a role ID?
correct
Does that even work?
yea it does
Didn't know that.
But since you changed the code, I'm assuming you're getting a different error than before or?
I doubt that'd fix the issue
Im not entirely sure how the discord permissions would look correct
try getting the role obj via
https://discord.js.org/#/docs/discord.js/14.4.0/class/RoleManager?scrollTo=cache
and log it
is this something I can new up
As long as the bot is above the member it tries to add a role to, it should be fine.
yea
maybe I should just try to use the client to do this instead of the interaction?
Can you try this tho?
yeah im doing that now, just trying to figure out the simplest way to get that information
My guess would be interaction.guild.roles.cache.get(roleID)
^
the above returns [CLIENT-BOT] | Role: <@&981266467976781905> | 10/10/2022, 7:37:44 PM
well
&981266467976781905
specifically returns <@&981266467976781905 >
and 981266467976781905 matches the id of the role ur attempting to add?
yes
Alright, so the role exists and the bot is above that role, right?
yes
can u log all the clients permissions? sorry for the random requests im just confused on this
I called that out above, that I checked that the role of the bot was above all other roles in the server.
interaction.guild.members.me.permissions
oh good idea
PermissionsBitField { bitfield: 987640626271n }
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
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
the toolkit bot has a neat cmd for that :)
very nice, great info
can u directly log roleIds and show the output, just in case
The only thing I can come up with is the role not being an actual role at this point
yeah one moment
which is strange becuase it resolved into one
^
I don't get how it would give this output 👀
Can you show the exact code where you're getting and logging it
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.
Can you try ```js
let role = interaction.guild.roles.cache.get('roleID')
console.log(role)
direct console log of roleIds: RoleIds 981266467976781905
console.log('RoleIds', roleIds)
Cause that's just returning the role mention and that's not really helpful 😄
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?
really you could just do
export const consoleLogMessageWithType = (message: string, type: string) => {
console.log(`[${type.toUpperCase()}] | ${message} | ${new Date().toLocaleString()}`);
}
logging a role obj should give some more insight, worth a try
^
I could - however I have other things I am doing inside the switch under certain circumstances that I didn't include as to not further push the topic away from my actual issue.
a template literal will add it as part of the string, which will be a mention, while logging separately will log the whole object
oh alright
I do appreciate the idea though!
name: 'Oceanology 5'
is that the correct guild?
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.
is the role attempting to be added an administrator role
let me verify
doesnt look like it from the perm bitfield but j in case
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
me too
looks like thats out of the question now
im convinced thsi is some obscure api error
I have to ask - you 1) saved the code and 2) restarted the bot after, right?
And you did try to readd the bot too right?
tried to what?
Re-add
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?
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?
Im trying to think out of the box at this point lol
like instead of supplying roleIds supply some other role id in a string
let me try to call the api end point directly
Idk if this has any impact, but would this work: ```js
interaction.member?.roles.add(roleIds, 'Verified ownership of the product via automated slash command.')
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.
Ahh oka, I don't use typescript so I wouldn't know xd
yea it forces u to cast it right
u can try that as well
fwiw
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?
I tried with the role object
if it wasnt cached it wouldnt be able to be gotten via cache.get
headed to postman to try and put the endpoint
yeah post man says the same
{
"message": "Missing Access",
"code": 50001
}
try using a different role
Looking at other issues, regenerating your bot's token is a possible fix?
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
Which intents do you have enabled? Both on the D dev portal and in your code
const client = new DiscordClient({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildIntegrations
],
});
GuildMemberResolvable and UserResolvable are the same
ok so I just entered here and was at the top
And had to scroll down 
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.
Missing Access
the bot isn't in the guild ig
should I move this over to the official discord?
ok I'm out
too much missing context
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
For the most recent the guild owner checked every permission possible.
yes
can you show the full error
A Discord bot for managing your discord roles for products you sell on the unreal engine marketplace
that is the full error
oh
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.
You wouldn't get that error from ratelimits though
yeah I figured I wouldn't but it was worth the sanity check
True. Are you sure about where it breaks btw?
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
Can you maybe resend the code in a codeblock so it's easier to see
Is this possibly because my bot isn't verified and its in a very large server
no
Nope.
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
The command is being used in the same guild as the role is in ye?
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
maybe the api isn’t recognizing that ur bots in the server for whatever reason
...
You cannot add bot roles
that’s his bots role
not the one he’s trying to add
im not trying to add roles..
should I move over to discord and ask there?
can u give the bot admin or something
like the admin role
try this
you're using the right token, right?
<guild>.roles.setPosition(roleIds, 7)
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?
The role will just get a different position in the roles section
yeah i am using the correct token
itll just move it down some positions, it doesnt look like that role has any permissions that would cause alarm. you can ask the owner for perms to do so if u want first
Although, I don't think it's smart to move that role above the Admin role
Wait, now I'm confused.
the only reason i suggest it is because for whatever reason its not getting position value correctly
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.
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
what about the role ur trying to adds position
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
Makes sense looking at this image
The bot's role's position should be 7, not 1
Position 1 is the lowest role.
position 1 is the lowest?
did not know that, thank u mazikeen
So yeah it looks like the API quite isn't following 🤷♀️
so you are saying the positions should go like that?
everyone is 0
well no ur bot is where its supposed to be
but for whatever reason the api thinks otherwise
Not according to the API since it says position 1
but now it's saying 1
and when the owner gave the bot the admin role it still didnt work ?
correct
Can you send a new image of the roles and log the bot's role once again?
just asked the server owner to do so
Yeah, which is even more confusing. But it is at 1 right now?
If it is at 1 in the roles section aswell, try changing it's position to e.g. 3, save, and back to 7
did I miss something
because if the problem is role positions, the error should be Missing Permissions
this fixed the issue
moved it to 2
then moved it to 6
it now works
and permissions are added
Great
i guess not
that is so so strange
well better late than never
Glad it worked out so quickly xd
How do I after action this lol.
what
How do I describe why this happened; when the position were originally correct and it was not working.
Discord's API just being Discord's API. 😄
I guess the solution if this happens to other customers in the future would be to move the position multiple times?
yeah, shuffle them around then set them back
Thank you everyone for walking through this with me and helping me troubleshoot this not so obvious error.
though this shouldnt reoccur i hope
No problems, only lost 3 hours of sleep 😴 xd
@mental frigate Have you tried this?
nope