Permission or Role check with decorators
is it possible with sapphire something like
if user has role with id "1098270502058995842"
or if user has role "Moderator(Object)"
Solution:Jump to solution
```ts
import type { Message } from 'discord.js';
import { createFunctionPrecondition } from '@sapphire/decorators';
export function RequiresRoleAccess(): MethodDecorator {...
14 Replies
we don't have a built in decorator for it but you can totally write your custom one yes
ah like preconditions ?
Solution
(replace
message: Message
with for example interaction: Command.ChatInputCommandInteraction
for chat input run)Sapphire Framework
Creating your own preconditions | Sapphire
Just as we did in Creating Commands, we will start by creating a preconditions subdirectory in
i just follow this
that's not a decorator
anyways thanks
yea yea
you asked for decorators
can't i code like this but decorator version
what am i talking about
idk you tell me what you're talking about
i was surfing at docs and this seems fine
maybe in the future i'll try decorators but
i just wanted to try this precondition
for experience
The way decorators work internally they will never be preconditions. Decorators work by first processing the decorator function, then calling the original function with
originalMethod.call(this, ...args)
. Preconditions however, run explicitly before the messageRun
etc is actually called, that is to say, before decorators are even considered.maybe i'll try this too
who knows
btw is it possible to hide command from member who doesn't have permission
for chat input commands you set
setDefaultMemberPermissions
in the registry and beyond that it's up to the digression of the server owners. That said, do not let it be the only check, because a server owner can theoretically allow @ everyone to use for example ban
and then blame you as a bot developer for the fact that a member just banned the staff.