Is there a good way to check whether a user is eligible to run a command?

I want to check whether a user is eligible to run a command via Discord's integration command permissions. Is there a viable way to do that?
11 Replies
d.js toolkit
d.js toolkitā€¢9mo 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!
duck
duckā€¢9mo ago
if the permissions are already set in the integrations tab of the server's settings, they will be unable to use the command if they lack the permissions required
OIRNOIR
OIRNOIRā€¢9mo ago
I understand that. I want to make a certain command's permissions also apply to a component (button). How can I do that? Is this to say that everything needs to be checked manually at this time? It would be cool if there was a helper function in GuildMember or something or GuildApplicationCommandManager Thank you though
duck
duckā€¢9mo ago
it'd be a little harder to implement such a feature I believe command permissions can be fetched with a bot, but they aren't cached on ready therefore you'd need to fetch them yourself with <ApplicationCommandManager>.permissions.fetch() but beyond this, <ApplicationCommandManager>.permissions.has() does seem to exist as seen in the flow chart, it's a little complicated to implement even beyond just this
OIRNOIR
OIRNOIRā€¢9mo ago
Yeah Anyway, if someone doesn't put in the work to implement it as a d.js helper function, I'm going to put in the work to implement that flow chart into a helper function in my project If i do that maybe I'll see if I can PR it, although I don't use typescript I was under the impression that it was typescript, for some reason. That's good, then. šŸ‘ If permissions are being fetched, to reasonably work at scale in a library it would need its own cache. If this isn't populated on ready, it would have to be an async function to allow for the possibility of a fetch being preformed.
duck
duckā€¢9mo ago
I imagine it'd be better for it to be synchronous and simply rely on the cache in the same way <GuildChannel>.permissionsFor() does, returning null if permissions are unable to be resolved at all
OIRNOIR
OIRNOIRā€¢9mo ago
That's fair. Does a cache for application command permissions exist? There would need to be a note of some sort to explain to the developer to fetch them beforehand to populate the cache to avoid this. there was an attempt to add a reaction on a message Interesting That means one would either have to fetch them every time (which is probably a waste) or set a set cache time (which runs the risk of going based on an outdated cache) In either case it would unfortunately probably have to be asynchronous since there isn't a pre-populated cache That's understandable, but in my opinion this could be widely useful for the discord.js community. If it has some quirks, we should try to not let those get in the way. Of course. I just wish there was a more viable way to make a specific component's required permissions the same as a command's.
OIRNOIR
OIRNOIRā€¢9mo ago
when discord listens to its users Thanks for the help though Note: <ApplicationCommandPermissionsManager>.has() seems to be badly documented: The example says:
// Check whether a user has permission to use a command
But the function actually simply checks whether or not an override exists for the specified channel/role/user id (or the whole bot, if you pass client.user.id). It returns true if there is an override, false if there isn't.
duck
duckā€¢9mo ago
it seems to just be the example the actual description of the method Check whether a permission exists for a user, role, or channel, while awkwardly worded, appears to be accurate the dapi docs just refer to these as "application command permissions", so each individual object is "a permission" the example's comment should probably be updated, but also I'm personally a little unsure about why this method was implemented in the first place or in general what purpose it could serve as is
OIRNOIR
OIRNOIRā€¢9mo ago
Yep. I ran into a problem while checking these. How do I find the overwrite for the "All Channels" option you can set on command overwrites? In my server it seems to be exactly one less than the guild ID, but I can't verify that this is the same in all cases. Nevermind, I checked the API documentation and that's literally what it is for some reason https://discord.com/developers/docs/interactions/application-commands#application-command-permissions-object-application-command-permissions-constants that sounds like such a hacky way to implement it but ok if i were writing this library i would include a handy link to https://discord.com/developers/docs/interactions/application-commands#permissions on that page or at least a description that "oh, the atEveryone role is the guild id and the All Channels option is the guild id minus one" god I love BigInts
String(BigInt(guildId) - 1n)
String(BigInt(guildId) - 1n)
Want results from more Discord servers?
Add your server