Roc
Roc
DIAdiscord.js - Imagine an app
Created by Roc on 11/26/2023 in #djs-questions
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.
5 replies