(solved) Strange permissions error inside discordjs that I cant catch and cant replicate?

Once in a while I will receive a strange error from discordjs that will crash my entire bot, and a try/catch block in the area of my code that seems to cause the issue doesnt ever catch the error. Instead it seems to be internal to discordJS and unavoidable.
/Users/mistersircode/Documents/GitHub/Arthur/node_modules/@discordjs/rest/dist/index.js:727
throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
^

DiscordAPIError[50013]: Missing Permissions
at handleErrors (/Users/mistersircode/Documents/GitHub/Arthur/node_modules/@discordjs/rest/dist/index.js:727:13)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async SequentialHandler.runRequest (/Users/mistersircode/Documents/GitHub/Arthur/node_modules/@discordjs/rest/dist/index.js:1128:23)
at async SequentialHandler.queueRequest (/Users/mistersircode/Documents/GitHub/Arthur/node_modules/@discordjs/rest/dist/index.js:959:14)
at async _REST.request (/Users/mistersircode/Documents/GitHub/Arthur/node_modules/@discordjs/rest/dist/index.js:1272:22)
at async TextChannel.send (/Users/mistersircode/Documents/GitHub/Arthur/node_modules/discord.js/src/structures/interfaces/TextBasedChannel.js:182:15) {
requestBody: {
files: [],
json: {
content: undefined,
tts: false,
nonce: undefined,
enforce_nonce: false,
embeds: [ { fields: [ [Object], [Object], [Object] ] } ],
components: undefined,
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: undefined,
message_reference: { message_id: '1348386197726167070', fail_if_not_exists: true },
attachments: undefined,
sticker_ids: undefined,
thread_name: undefined,
applied_tags: undefined,
poll: undefined
}
},
rawError: { message: 'Missing Permissions', code: 50013 },
code: 50013,
status: 403,
method: 'POST',
url: 'https://discord.com/api/v10/channels/1201565597453009018/messages'
}
/Users/mistersircode/Documents/GitHub/Arthur/node_modules/@discordjs/rest/dist/index.js:727
throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
^

DiscordAPIError[50013]: Missing Permissions
at handleErrors (/Users/mistersircode/Documents/GitHub/Arthur/node_modules/@discordjs/rest/dist/index.js:727:13)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async SequentialHandler.runRequest (/Users/mistersircode/Documents/GitHub/Arthur/node_modules/@discordjs/rest/dist/index.js:1128:23)
at async SequentialHandler.queueRequest (/Users/mistersircode/Documents/GitHub/Arthur/node_modules/@discordjs/rest/dist/index.js:959:14)
at async _REST.request (/Users/mistersircode/Documents/GitHub/Arthur/node_modules/@discordjs/rest/dist/index.js:1272:22)
at async TextChannel.send (/Users/mistersircode/Documents/GitHub/Arthur/node_modules/discord.js/src/structures/interfaces/TextBasedChannel.js:182:15) {
requestBody: {
files: [],
json: {
content: undefined,
tts: false,
nonce: undefined,
enforce_nonce: false,
embeds: [ { fields: [ [Object], [Object], [Object] ] } ],
components: undefined,
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: undefined,
message_reference: { message_id: '1348386197726167070', fail_if_not_exists: true },
attachments: undefined,
sticker_ids: undefined,
thread_name: undefined,
applied_tags: undefined,
poll: undefined
}
},
rawError: { message: 'Missing Permissions', code: 50013 },
code: 50013,
status: 403,
method: 'POST',
url: 'https://discord.com/api/v10/channels/1201565597453009018/messages'
}
24 Replies
d.js toolkit
d.js toolkit2mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by staff
treble/luna
treble/luna2mo ago
its not an internal error you just try to send a message to a channel the bot doesnt have access to
SirCode
SirCodeOP2mo ago
Thats the issue... It works sometimes, and doesnt other times Its inconsistent Ill run the bot locally on my main rig and send the same identical command to the same channel and itll work but wait a week when its running on the main server, and boom it randomly dies after sending a command
treble/luna
treble/luna2mo ago
does the bot have the ReadMessageHistory permission
SirCode
SirCodeOP2mo ago
its an admin
SirCode
SirCodeOP2mo ago
I use message.reply most of the time, such as this
No description
SirCode
SirCodeOP2mo ago
Oh shit really? huh.. The more you know
treble/luna
treble/luna2mo ago
but sounds like your bot doesnt have permission to read message history (or just viewchannel at all)
SirCode
SirCodeOP2mo ago
Bot's internal role
No description
SirCode
SirCodeOP2mo ago
Bot is visible in the channel member list has full admin on his top level role anyways :cat_happycry:
treble/luna
treble/luna2mo ago
and is the channel id 1201565597453009018
SirCode
SirCodeOP2mo ago
1201565597453009018 Copied directly yup My personal server. Its just the general channel lol it doesnt have any fancy permission requirements ironically the command doesnt error out in my private mod channel only the general channel :concernwilde: And the bot is an admin anyways so I dont get it lol
d.js docs
d.js docs2mo ago
:method: BaseGuildVoiceChannel#permissionsFor() [email protected] Gets the overall set of permissions for a member or role in this channel, taking into account channel overwrites.
treble/luna
treble/luna2mo ago
.toArray that for the bot log it and show the output
SirCode
SirCodeOP2mo ago
Does the bot have a quick reference to grab the guildmember? I havent worked on this in months lol, I dont remember immediately
treble/luna
treble/luna2mo ago
<Guild>.members.me
SirCode
SirCodeOP2mo ago
gotcha
SirCode
SirCodeOP2mo ago
No description
SirCode
SirCodeOP2mo ago
Definitely has readmessagehistory like, thats the same channel, and that command worked (its not a slash command, but an internal command... same type as the one that crashes it) Theyre doing the same thing So Im not sure why one would inconsistently crash it Anyways I got all the awaits and stuff in so hopefully that wont kill the bot again next time but rather just send the error to me
SirCode
SirCodeOP2mo ago
No description
SirCode
SirCodeOP2mo ago
Yup haha I genuinely dont get it it literally sees the message, replied to me HOW is it failing :kekw:
SirCode
SirCodeOP2mo ago
Full stack
SirCode
SirCodeOP2mo ago
Code
No description
SirCode
SirCodeOP2mo ago
Oh? perhaps I was mistaken one moment Ah Probably it Yeah I just appended admin to the bots internal role and that fixed it lol so goofy of me Well, fixed two birds with one stone... Hopefully no more death by permission error

Did you find this page helpful?