Trying to change a channel name only works when my bot gets the admin role.

I've got some simple DiscordJS code that is trying to set the name of a specific channel. The problem is that this only succeeds when i assign the bot the Administrator role. From what I read in the manual, having the Manage Channel role should be sufficient, but that doesn't seem to be the case. I made sure that the bot has server-wide MANAGE_CHANNEL rights, I have added the MANAGE_CHANNEL permission to the bot Role itself, and added it to both the channel category as well as the channel. But I keep getting DiscordAPIError[50001]: Missing Access Am I wrong in thinking that the MANAGE_CHANNELS permission is enough ?
27 Replies
d.js toolkit
d.js toolkit•2d 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!
oenieke
oeniekeOP•2d ago
Screenshots of said permissions
No description
No description
No description
monbrey
monbrey•2d ago
If Discord is denying it then yeah, in this situation it isnt enough. e.g, something like having Manage Channel but not View Channel
oenieke
oeniekeOP•this hour
Well, i have given it all of the channel permissions i could think of The strange thing is that my own user, which DOESN'T have the administrator permission, is able to create channels and change their names. Which doesn't quite make sense to me
clownidze
clownidze•this hour
mind showing your code?
oenieke
oeniekeOP•this hour
Sure, it's pretty simple
const {Client, Events, GatewayIntentBits} = require('discord.js');
var http = require('http');
var agent = new http.Agent({ family: 4 });
const axios = require('axios');
var instance = axios.create({ httpAgent: agent });

require('dotenv').config();

const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] });
const testChannelID = process.env.TEST_CHANNEL_ID;


client.on('ready', async () => {
console.log(`Logged in as ${client.user.tag}`);
await updateChannelName(testChannelID);
});

async function updateChannelName(channelID) {
let floorChannel = client.channels.cache.get(channelID);

if (floorChannel) {
try {
let updatedChannel = await floorChannel.setName('New channel name');
} catch(error) {
console.error(`Error renaming channel: ${error}`);
}
}
}


client.login(process.env.DISCORD_TOKEN);
const {Client, Events, GatewayIntentBits} = require('discord.js');
var http = require('http');
var agent = new http.Agent({ family: 4 });
const axios = require('axios');
var instance = axios.create({ httpAgent: agent });

require('dotenv').config();

const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] });
const testChannelID = process.env.TEST_CHANNEL_ID;


client.on('ready', async () => {
console.log(`Logged in as ${client.user.tag}`);
await updateChannelName(testChannelID);
});

async function updateChannelName(channelID) {
let floorChannel = client.channels.cache.get(channelID);

if (floorChannel) {
try {
let updatedChannel = await floorChannel.setName('New channel name');
} catch(error) {
console.error(`Error renaming channel: ${error}`);
}
}
}


client.login(process.env.DISCORD_TOKEN);
It works fine when the bot has administrator permissions
monbrey
monbrey•this hour
Its unlikely to be code related, just something in the permissions hierarchy e.g., being blocked at the category level
oenieke
oeniekeOP•this hour
Discord API only mentions the MANAGE_CHANNELS permission
No description
oenieke
oeniekeOP•this hour
But if you look at the screenshots higher up, it seems like it has all permissions on all levels But i suppose there must be some kind of strange setting there that still disallows it somehow
monbrey
monbrey•this hour
Its the API disagreeing with you, not discord.js. There's very little we can do, youd be better off checking with Discord API or Discord Developers
oenieke
oeniekeOP•this hour
I suppose you're right
monbrey
monbrey•this hour
I agree, it all looks right from what youve shown
oenieke
oeniekeOP•this hour
I'll look into what permissions it detects with discordjs for said bot. The config looks allright, so i must be doing something wrong that I think I'm doing right 😄 After 20+ years of dev work that still happens on a weekly basis 😄
clownidze
clownidze•this hour
so, i ran your code with a freshly created bot and added to guild using those permissions:
No description
clownidze
clownidze•this hour
everything works completely fine
oenieke
oeniekeOP•this hour
hmmm weird
clownidze
clownidze•this hour
didnt even change perms for channel and role
oenieke
oeniekeOP•this hour
thanks for that
clownidze
clownidze•this hour
ill do some testing rn and tell u in which cases it doesnt work i got the same error when: 1. added bot with View Channels and Manage Channels perms on server 2. created new text channel under private category with permissions syncing, where perm View Channel was denied for @everyone 3. tried to modify that channel so simply, bot doesnt has access to that channel
oenieke
oeniekeOP•this hour
well if i ask for the permissions, it says
'ManageChannels',
'ManageGuild',
'AddReactions',
'ViewAuditLog',
'Stream',
'ViewChannel',
'ManageChannels',
'ManageGuild',
'AddReactions',
'ViewAuditLog',
'Stream',
'ViewChannel',
Both on the server as for the specific channel
clownidze
clownidze•this hour
No description
clownidze
clownidze•this hour
i gave the role those perms in private category and it seems to be working again *i have enabled permission syncing for channels inside of that category check permissions for role in server settings and simply double check channel id and other info
oenieke
oeniekeOP•this hour
I did this:
// Fetch the guild
const guild = await client.guilds.fetch(guildId);

// Fetch the bot's member object in the guild
const botMember = await guild.members.fetch(client.user.id);

// Check the bot's permissions in the guild
const botPermissions = botMember.permissions;
// Fetch the guild
const guild = await client.guilds.fetch(guildId);

// Fetch the bot's member object in the guild
const botMember = await guild.members.fetch(client.user.id);

// Check the bot's permissions in the guild
const botPermissions = botMember.permissions;
and that gave the same permissions as on the channel itself anyway, i'll do some more testing, see if I can find anything wrong. Just weird that its acting this way Yeah, ok so definitely something fishy with the permissions on some level. Just added a new. pristine channel, and I could just change its name Thanks @clownidze to check with me.
clownidze
clownidze•this hour
yeah, that permissions thing without administrator is hell to set up correctly :blobguns:
oenieke
oeniekeOP•this hour
OK, so it works once I clicked the sync permission thingy on the category I also gave View Channels to @ everyone
Patrick
Patrick•17h ago
@oenieke @clownidze Permissions in Discord are sometimes implicitly denied or allowed based on logical use. For voice and stage channels, denying the CONNECT permission also implicitly denies other permissions such as MANAGE_CHANNEL. Turning a Voice Channel private automatically denies both VIEW_CHANNEL and CONNECT permissions on that channel thus inadvertently also stopping a non administrator from managing it. This specific behavior is mention in Discord's Developer Documentation under the section Implicit Permissions
No description
oenieke
oeniekeOP•16h ago
Thanks for the info !

Did you find this page helpful?