Gravvy
Gravvy
DIAdiscord.js - Imagine an app
Created by Gravvy on 8/21/2024 in #djs-questions
Unable to change USE_EXTERNAL_APPS permission
Hello, I am trying to change the USE_EXTERNAL_APPS permission for a role in a channel. However I am encountering an issue. Below is the code and the error message. It's been some time since I did anything with discord.js so I may just be misremembering the process. Code
const channels = interaction.guild.channels.cache;
channels.forEach(channel => {
channel.permissionOverwrites.edit(`212635560596996097`, { USE_EXTERNAL_APPS: false });
});
return interaction.reply({ content: 'Permissions updated.', ephemeral: true });
const channels = interaction.guild.channels.cache;
channels.forEach(channel => {
channel.permissionOverwrites.edit(`212635560596996097`, { USE_EXTERNAL_APPS: false });
});
return interaction.reply({ content: 'Permissions updated.', ephemeral: true });
Error
RangeError [BitFieldInvalid]: Invalid bitfield flag or number: USE_EXTERNAL_APPS.
at PermissionsBitField.resolve (C:\Users\dedicated\Desktop\DiscordBot\node_modules\discord.js\src\util\BitField.js:174:11)
at PermissionsBitField.remove (C:\Users\dedicated\Desktop\DiscordBot\node_modules\discord.js\src\util\BitField.js:105:33)
at PermissionOverwrites.resolveOverwriteOptions (C:\Users\dedicated\Desktop\DiscordBot\node_modules\discord.js\src\structures\PermissionOverwrites.js:130:15)
at PermissionOverwriteManager.upsert (C:\Users\dedicated\Desktop\DiscordBot\node_modules\discord.js\src\managers\PermissionOverwriteManager.js:105:50)
at PermissionOverwriteManager.edit (C:\Users\dedicated\Desktop\DiscordBot\node_modules\discord.js\src\managers\PermissionOverwriteManager.js:150:17)
at C:\Users\dedicated\Desktop\DiscordBot\commands\Moderator\permission.js:14:42
at _Collection.forEach (<anonymous>)
at Object.execute (C:\Users\dedicated\Desktop\DiscordBot\commands\Moderator\permission.js:13:18)
at Object.execute (C:\Users\dedicated\Desktop\DiscordBot\events\interactionCreate.js:14:31)
at Client.<anonymous> (C:\Users\dedicated\Desktop\DiscordBot\functions\handleEvents.js:8:58) {
code: 'BitFieldInvalid'
}
RangeError [BitFieldInvalid]: Invalid bitfield flag or number: USE_EXTERNAL_APPS.
at PermissionsBitField.resolve (C:\Users\dedicated\Desktop\DiscordBot\node_modules\discord.js\src\util\BitField.js:174:11)
at PermissionsBitField.remove (C:\Users\dedicated\Desktop\DiscordBot\node_modules\discord.js\src\util\BitField.js:105:33)
at PermissionOverwrites.resolveOverwriteOptions (C:\Users\dedicated\Desktop\DiscordBot\node_modules\discord.js\src\structures\PermissionOverwrites.js:130:15)
at PermissionOverwriteManager.upsert (C:\Users\dedicated\Desktop\DiscordBot\node_modules\discord.js\src\managers\PermissionOverwriteManager.js:105:50)
at PermissionOverwriteManager.edit (C:\Users\dedicated\Desktop\DiscordBot\node_modules\discord.js\src\managers\PermissionOverwriteManager.js:150:17)
at C:\Users\dedicated\Desktop\DiscordBot\commands\Moderator\permission.js:14:42
at _Collection.forEach (<anonymous>)
at Object.execute (C:\Users\dedicated\Desktop\DiscordBot\commands\Moderator\permission.js:13:18)
at Object.execute (C:\Users\dedicated\Desktop\DiscordBot\events\interactionCreate.js:14:31)
at Client.<anonymous> (C:\Users\dedicated\Desktop\DiscordBot\functions\handleEvents.js:8:58) {
code: 'BitFieldInvalid'
}
npm ls discord-api-types https://i.imgur.com/2QGQCIb.png Node.js is v21.6.0
14 replies
DIAdiscord.js - Imagine an app
Created by Gravvy on 11/22/2022 in #djs-questions
.setNickname returning Missing Privileges error
Hey there, I'm writing a simply change nickname command and for some reason, I'm getting an error of Missing Permissions. Now I have my bot set as an Administrator, it's role above everyone else. And the account I'm running the command on is a test account with no special permissions or roles. The test account is below the bot in hierarchy. Yet I'm still getting this error. And I just too tired to see the error I've made? Steps I've taken to resolve the issue: * Test account has no roles * Bot role hierarchy is top most * Bot has Administrator privileges * Confirmed member object is being returned correctly * Confirmed all Intents required are added Command code
const { EmbedBuilder, SlashCommandBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('nickname')
.setDescription('Change your name')
.addStringOption(option =>
option.setName('name')
.setDescription('Enter your new nickname')
.setRequired(true)),
async execute(client,interaction) {
const name = interaction.options.getString('name');
const userid = interaction.user.id;

const guild = client.guilds.cache.get(`${process.env.guildID}`);
await guild.members.fetch(`${userid}`).then(async member => {
return member.setNickname(`${name}`).catch(async err => {
return console.log(err);
});
}).catch(async err => {
return console.log(err);
});
},
};
const { EmbedBuilder, SlashCommandBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('nickname')
.setDescription('Change your name')
.addStringOption(option =>
option.setName('name')
.setDescription('Enter your new nickname')
.setRequired(true)),
async execute(client,interaction) {
const name = interaction.options.getString('name');
const userid = interaction.user.id;

const guild = client.guilds.cache.get(`${process.env.guildID}`);
await guild.members.fetch(`${userid}`).then(async member => {
return member.setNickname(`${name}`).catch(async err => {
return console.log(err);
});
}).catch(async err => {
return console.log(err);
});
},
};
Have all my intents in place
const { Client, Collection, GatewayIntentBits, Partials } = require('discord.js');
const client = new Client({ intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildIntegrations,
GatewayIntentBits.GuildBans,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.DirectMessageReactions,
GatewayIntentBits.MessageContent,
], partials: [
Partials.Message,
Partials.Channel,
Partials.Reaction
] });
const { Client, Collection, GatewayIntentBits, Partials } = require('discord.js');
const client = new Client({ intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildIntegrations,
GatewayIntentBits.GuildBans,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.DirectMessageReactions,
GatewayIntentBits.MessageContent,
], partials: [
Partials.Message,
Partials.Channel,
Partials.Reaction
] });
I'm pretty sure the issue is just me being blind, but I am at a loss right now as to why it's erroring out.
4 replies