-
Notifications
You must be signed in to change notification settings - Fork 0
Permissions
Halpbot provides support for three different ways of determining if a member has permission to use a command. These three different ways can all be used in conjunction with each other in the @Permissions decorator. These are summarised below:
- Using JDA's built-in
Permissionenum to check the member's permissions. - Defining permission suppliers which verifies if a member has the permission by calling a custom method.
- Binding roles to permissions and checking if the member has the necessary roles.
For basic usage of the @Permissions decorator and some examples, refer to the documentation here.
Permission suppliers are methods annotated with @PermissionSupplier that only take in a Guild and Member respectively and return a boolean, defining if the member has the specified permission within that guild. The class these methods are defined in must be annotated with @Service. Halpbot comes with two permission suppliers built in:
| Permission | Description |
|---|---|
HalpbotPermissions.BOT_OWNER |
Returns true if the member is the owner of the bot defined in the bot-config. |
HalpbotPermissions.GUILD_OWNER |
Returns true if the member is the owner of the guild that the action was invoked in. |
NOTE: Permission suppliers will be automatically registered on startup. If they don't match the requirements defined previously, then a warning will be logged into the console and the permission supplier ignored.
Consider the permission suppliers for the built-in BOT_OWNER and GUILD_OWNER permissions. Notice that you can inject dependencies into the class if needed.
Show Imports
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import org.dockbox.hartshorn.core.annotations.stereotype.Service;
import javax.inject.Inject;
import nz.pumbas.halpbot.HalpbotCore;@Service
public class HalpbotPermissions
{
@Inject private HalpbotCore halpbotCore;
public static final String BOT_OWNER = "halpbot.bot.owner";
public static final String GUILD_OWNER = "halpbot.guild.owner";
@PermissionSupplier(GUILD_OWNER)
public boolean isGuildOwner(Guild guild, Member member) {
return guild.getOwnerIdLong() == member.getIdLong();
}
@PermissionSupplier(BOT_OWNER)
public boolean isBotOwner(Guild guild, Member member) {
return this.halpbotCore.ownerId() == member.getIdLong();
}
}- Built-in Commands
- @Command Parameters
- Arguments
- Annotations
- Custom Objects
- Custom TypeParsers
- Slash Commands - W.I.P.
- Pagination - W.I.P