Checking permission to create channels/roles

I have a command which can create a channel and/or role so I have code to ensure the bot has the correct permission to do so as shown below:
public static async canCreateChannel(guild: Guild): Promise<boolean> {
let botMember = await guild.members.fetchMe();

if (!botMember) return false;

return botMember.permissions.has(PermissionFlagsBits.ManageChannels);
}
public static async canCreateChannel(guild: Guild): Promise<boolean> {
let botMember = await guild.members.fetchMe();

if (!botMember) return false;

return botMember.permissions.has(PermissionFlagsBits.ManageChannels);
}
After I check this I then proceed to create the channel as shown in the screenshot. For the majority of servers this seems to work, but for some reason I still get some errors in my logs for Missing Permission (also shown in a screenshot) when trying to create either the channel or role.
6 Replies
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
Stqlth
StqlthOP2y ago
Am I checking the permission wrong or missing something?
!"Unkown
!"Unkown2y ago
u can always try to create the channel and catch it if its fails
Stqlth
StqlthOP2y ago
Yea I just would like to prevent that call if possible I don't assign it to a parent could you reword this?
Stqlth
StqlthOP2y ago
I do
Stqlth
StqlthOP2y ago
I see what you are saying I need all those I have set in allow for the bot 👍 Thanks! you guys should let normal members use reactions in forums 😂 @qjuh are you certain this is the case? I just tested where my Bot only had 4 permissions: View Channels, Manage Roles, Manage Channels and Send Messages & Create Posts while the @everyone role had all permission turned off, but the bot can still make a channel with the overrides I have listed above Also, I can confirm this also happens for the when creating a role so I know the only issue, if it is one, can't be the overrides
Want results from more Discord servers?
Add your server