Invite Permission Issue

(@ to reply) (repost from #djs-help-v14 but escalating) I am having an issue creating an invite using discord.js v14.14.1 When the bot has administrator permissions this code works just fine, but when the bot is added to a server with the CreateInstantInvite and no admin permissions I get a DiscordAPIError[50013]: Missing Permissions error. This has been reproduced in a few other servers and I've had the same issue
// events/interaction.js

// * Imports
const { Events, EmbedBuilder, PermissionFlagsBits } = require("discord.js");

// Event handling ...

// * CreateInvite Button Interaction

// Check perms
const botPermissions =
await interaction.guild.members.me.permissionsIn(
interaction.channel
);

const hasInvPerm = botPermissions.has(
PermissionFlagsBits.CreateInstantInvite
); // ! Returns true when testing

// If no perms
if (!hasInvPerm) {
const embed = new EmbedBuilder()
.setColor(config.colors.secondary)
.setDescription(
`${config.emojis.no} I do not have the needed permissions to create an invite.`
);
return interaction.reply({
embeds: [embed],
ephemeral: true,
});
}

// Delete and create invite
const invites = await interaction.guild.invites.fetch();

const botInvites = invites.filter(
(invite) =>
invite.inviter.id === interaction.client.user.id
);

const invite = await interaction.guild.invites.create(
interaction.channel.id,
{ maxAge: 0 }
);
// events/interaction.js

// * Imports
const { Events, EmbedBuilder, PermissionFlagsBits } = require("discord.js");

// Event handling ...

// * CreateInvite Button Interaction

// Check perms
const botPermissions =
await interaction.guild.members.me.permissionsIn(
interaction.channel
);

const hasInvPerm = botPermissions.has(
PermissionFlagsBits.CreateInstantInvite
); // ! Returns true when testing

// If no perms
if (!hasInvPerm) {
const embed = new EmbedBuilder()
.setColor(config.colors.secondary)
.setDescription(
`${config.emojis.no} I do not have the needed permissions to create an invite.`
);
return interaction.reply({
embeds: [embed],
ephemeral: true,
});
}

// Delete and create invite
const invites = await interaction.guild.invites.fetch();

const botInvites = invites.filter(
(invite) =>
invite.inviter.id === interaction.client.user.id
);

const invite = await interaction.guild.invites.create(
interaction.channel.id,
{ maxAge: 0 }
);
When logging permissions I get this
console.log(await botPermissions.toArray());
console.log(await botPermissions.toArray());
[
'CreateInstantInvite', 'AddReactions',
'Stream', 'ViewChannel',
'SendMessages', 'ManageMessages',
'EmbedLinks', 'AttachFiles',
'ReadMessageHistory', 'UseExternalEmojis',
'Connect', 'Speak',
'UseVAD', 'ChangeNickname',
'UseApplicationCommands', 'RequestToSpeak',
'CreatePublicThreads', 'CreatePrivateThreads',
'UseExternalStickers', 'SendMessagesInThreads',
'UseEmbeddedActivities', 'UseSoundboard',
'UseExternalSounds', 'SendVoiceMessages'
]
[
'CreateInstantInvite', 'AddReactions',
'Stream', 'ViewChannel',
'SendMessages', 'ManageMessages',
'EmbedLinks', 'AttachFiles',
'ReadMessageHistory', 'UseExternalEmojis',
'Connect', 'Speak',
'UseVAD', 'ChangeNickname',
'UseApplicationCommands', 'RequestToSpeak',
'CreatePublicThreads', 'CreatePrivateThreads',
'UseExternalStickers', 'SendMessagesInThreads',
'UseEmbeddedActivities', 'UseSoundboard',
'UseExternalSounds', 'SendVoiceMessages'
]
I've removed the irrelevant parts of my code, but if you think anything is of interest let me know and I'll send it.
2 Replies
d.js toolkit
d.js toolkit13mo 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 OP
Roc
RocOP13mo ago
Stack trace:
DiscordAPIError[50013]: Missing Permissions
at handleErrors (C:\Users\Lostl\_CrystallineChronicles\_Sparked\Bot\node_modules\@discordjs\rest\dist\index.js:722:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (C:\Users\Lostl\_CrystallineChronicles\_Sparked\Bot\node_modules\@discordjs\rest\dist\index.js:1120:23)
at async SequentialHandler.queueRequest (C:\Users\Lostl\_CrystallineChronicles\_Sparked\Bot\node_modules\@discordjs\rest\dist\index.js:953:14)
at async _REST.request (C:\Users\Lostl\_CrystallineChronicles\_Sparked\Bot\node_modules\@discordjs\rest\dist\index.js:1266:22)
at async GuildInviteManager._fetchMany (C:\Users\Lostl\_CrystallineChronicles\_Sparked\Bot\node_modules\discord.js\src\managers\GuildInviteManager.js:160:18)
at async Object.execute (C:\Users\Lostl\_CrystallineChronicles\_Sparked\Bot\events\interaction.js:128:37) {
requestBody: { files: undefined, json: undefined },
rawError: { message: 'Missing Permissions', code: 50013 },
code: 50013,
status: 403,
method: 'GET',
url: 'https://discord.com/api/v10/guilds/1150487558116102197/invites'
}
DiscordAPIError[50013]: Missing Permissions
at handleErrors (C:\Users\Lostl\_CrystallineChronicles\_Sparked\Bot\node_modules\@discordjs\rest\dist\index.js:722:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (C:\Users\Lostl\_CrystallineChronicles\_Sparked\Bot\node_modules\@discordjs\rest\dist\index.js:1120:23)
at async SequentialHandler.queueRequest (C:\Users\Lostl\_CrystallineChronicles\_Sparked\Bot\node_modules\@discordjs\rest\dist\index.js:953:14)
at async _REST.request (C:\Users\Lostl\_CrystallineChronicles\_Sparked\Bot\node_modules\@discordjs\rest\dist\index.js:1266:22)
at async GuildInviteManager._fetchMany (C:\Users\Lostl\_CrystallineChronicles\_Sparked\Bot\node_modules\discord.js\src\managers\GuildInviteManager.js:160:18)
at async Object.execute (C:\Users\Lostl\_CrystallineChronicles\_Sparked\Bot\events\interaction.js:128:37) {
requestBody: { files: undefined, json: undefined },
rawError: { message: 'Missing Permissions', code: 50013 },
code: 50013,
status: 403,
method: 'GET',
url: 'https://discord.com/api/v10/guilds/1150487558116102197/invites'
}
Node:
v20.4.0
v20.4.0
Npm:
9.8.0
9.8.0
That worked! I hate how simple that was so fix. I've been spending so much time trying to fix it Thank you so much 😭
Want results from more Discord servers?
Add your server