requiredClientPermissions check always rejecting

While requiredUserPermissions: ['ManageRoles'] works great. The client check requiredClientPermissions: ['ManageRoles'] seems to always block. It is throwing not a specific missing permissions error but an I was unable to resolve my permissions in the ${commandType} command invocation channel. Unless I am doing something wrong, it looks like the problem is that the check is referencing the application id channel.permissionsFor(interaction.applicationId) when it should be referencing either the clients guild member or user ID. https://github.com/sapphiredev/framework/blob/179b21e7f74c4d9a506e1be98d7487f939ec0ae7/src/preconditions/ClientPermissions.ts#L71 When testing channel.permissionsFor(interaction.applicationId) always resolved null, where as channel.permissionsFor(interaction.client.user.id) and `channel.permissionsFor(interaction.guild.members.me) always gave a valid bitfield
"@sapphire/framework": "^4.2.0",
"discord.js": "^14.7.1",
"@sapphire/framework": "^4.2.0",
"discord.js": "^14.7.1",
GitHub
framework/ClientPermissions.ts at 179b21e7f74c4d9a506e1be98d7487f93...
Discord bot framework built on top of discord.js for advanced and amazing bots. - framework/ClientPermissions.ts at 179b21e7f74c4d9a506e1be98d7487f939ec0ae7 · sapphiredev/framework
Solution:
Closing this as the fix has been released in v4.2.1
Jump to solution
24 Replies
WhacK
WhacK2y ago
I use this on my bot and it works every time. I apply it via the decorator but I don’t think that matters. Did you ensure that permission was clicked when generating the invite? Mine used an admin link.
@ApplyOptions<ChatInputCommand.Options>({
name: 'travel',
description: 'Used to travel from area to area in Engrimoore',
requiredUserPermissions: [PermissionFlagsBits.SendMessages],
requiredClientPermissions: [PermissionFlagsBits.SendMessages, PermissionFlagsBits.ReadMessageHistory, PermissionFlagsBits.ManageRoles]
})
@ApplyOptions<ChatInputCommand.Options>({
name: 'travel',
description: 'Used to travel from area to area in Engrimoore',
requiredUserPermissions: [PermissionFlagsBits.SendMessages],
requiredClientPermissions: [PermissionFlagsBits.SendMessages, PermissionFlagsBits.ReadMessageHistory, PermissionFlagsBits.ManageRoles]
})
Deadlystrike
DeadlystrikeOP2y ago
The bot has been in my server for years, no clue how I invited it. For sanity sake I kicked it and re-invited it with a fresh invite link with all permissions selected &permissions=1099511627775&scope=bot - Additionaly upon joining I gave it an existing role that has admin perms in addition to the managed role it already had. Same output: 'I was unable to resolve my permissions in the chat input command invocation channel.'
WhacK
WhacK2y ago
Weird. I looked at my intents and nothing there to do with roles. Maybe someone smarter than I am can help
Favna
Favna2y ago
@Vladdy there shouldn't be a difference between the IDs?
vladdy
vladdy2y ago
Old applications have different ids Between app and user But I'm talking old old @Deadlystrike can you log your clients user id and the interactions applicationId please
Deadlystrike
DeadlystrikeOP2y ago
I do believe that I saw my client users id and the app id was different but let me recheck
vladdy
vladdy2y ago
You can see that in the dev portal too tbf
Deadlystrike
DeadlystrikeOP2y ago
they are diff
vladdy
vladdy2y ago
..how old is your app
vladdy
vladdy2y ago
Snow-Stamp
Discord Snowflake to Timestamp Converter
Get the exact time and date from a Discord Snowflake
Deadlystrike
DeadlystrikeOP2y ago
Dev Bot: 8/1/2016 Production Bot: 7/15/2016
vladdy
vladdy2y ago
.........first off thanks for using sapphire Secondly yeah that makes sense for it to break then @Favna we need a client user id fallback For all permission checks
Favna
Favna2y ago
fallback or just always use it
vladdy
vladdy2y ago
Fallback Any app past..2017 iirc has them tied I mean i suppose we can always use it
Favna
Favna2y ago
let permissions: PermissionsBitField | null = this.dmChannelPermissions;
if (interaction.inGuild()) {
permissions = channel.permissionsFor(interaction.applicationId);

if (isNullish(permissions)) {
permissions = channel.permissionsFor(interaction.client.user?.id);
}
}
let permissions: PermissionsBitField | null = this.dmChannelPermissions;
if (interaction.inGuild()) {
permissions = channel.permissionsFor(interaction.applicationId);

if (isNullish(permissions)) {
permissions = channel.permissionsFor(interaction.client.user?.id);
}
}
otherwise I'm doing this
vladdy
vladdy2y ago
... Are you high
Favna
Favna2y ago
no just tired from getting WoL not working
vladdy
vladdy2y ago
permissions = channel.permissionsFor(interaction.applicationId) ?? channel.permissionsFor(interaction.client.user?.id)
Favna
Favna2y ago
send my body a magic packet please
Favna
Favna2y ago
created a PR for this @Deadlystrike https://github.com/sapphiredev/framework/pull/616
GitHub
fix(ClientPermissions): fixed permission checking for old applicati...
Warning This Pull Request needs sapphiredev/utilities#559 to be approved and merged beforehand. Once the linked Pull Request is merged, this one will receive its last commit.
Deadlystrike
DeadlystrikeOP2y ago
🫡 building the branch now to test
Favna
Favna2y ago
If it gives type errors that's because of the linked PR and you can just ts-ignore any problematic lines for now Strangely it didn't give any in CI...
Deadlystrike
DeadlystrikeOP2y ago
Looking good so far, re-enabled the requiredClientPermissions checks and the command went through just fine, kicked the bot and re-invited with removed permissions and it threw a I am missing the following permissions to run this command: Manage Roles as i would expect.
Solution
Favna
Favna2y ago
Closing this as the fix has been released in v4.2.1
Want results from more Discord servers?
Add your server