Java Code Examples for net.dv8tion.jda.api.exceptions.HierarchyException

The following examples show how to use net.dv8tion.jda.api.exceptions.HierarchyException. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: JDA   Source File: RoleManagerImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected boolean checkPermissions()
{
    Member selfMember = getGuild().getSelfMember();
    if (!selfMember.hasPermission(Permission.MANAGE_ROLES))
        throw new InsufficientPermissionException(getGuild(), Permission.MANAGE_ROLES);
    if (!selfMember.canInteract(getRole()))
        throw new HierarchyException("Cannot modify a role that is higher or equal in hierarchy");
    return super.checkPermissions();
}
 
Example 2
Source Project: JDA   Source File: RoleImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public AuditableRestAction<Void> delete()
{
    Guild guild = getGuild();
    if (!guild.getSelfMember().hasPermission(Permission.MANAGE_ROLES))
        throw new InsufficientPermissionException(guild, Permission.MANAGE_ROLES);
    if(!PermissionUtil.canInteract(guild.getSelfMember(), this))
        throw new HierarchyException("Can't delete role >= highest self-role");
    if (managed)
        throw new UnsupportedOperationException("Cannot delete a Role that is managed. ");

    Route.CompiledRoute route = Route.Roles.DELETE_ROLE.compile(guild.getId(), getId());
    return new AuditableRestActionImpl<>(getJDA(), route);
}
 
Example 3
Source Project: SkyBot   Source File: SoftbanCommand.java    License: GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void execute(@Nonnull CommandContext ctx) {
    final List<String> args = ctx.getArgs();

    if (args.size() < 2) {
        this.sendUsageInstructions(ctx);
        return;
    }

    final List<Member> mentioned = ctx.getMentionedArg(0);

    if (mentioned.isEmpty()) {
        sendMsg(ctx, "I could not find any members with name " + args.get(0));
        return;
    }

    final Member toBanMember = mentioned.get(0);

    if (!canInteract(ctx.getMember(), toBanMember, "softban", ctx.getChannel())) {
        return;
    }

    try {
        final User toBan = toBanMember.getUser();
        if (toBan.equals(ctx.getAuthor()) && !ctx.getMember().canInteract(toBanMember)) {
            sendMsg(ctx, "You are not permitted to perform this action.");
            return;
        }

        String reason = "No reason given";
        final var flags = ctx.getParsedFlags(this);

        if (flags.containsKey("r")) {
            reason = String.join(" ", flags.get("r"));
        }

        final String fReason = reason;

        ctx.getGuild().ban(toBanMember, 1, fReason)
            .reason("Kicked by: " + ctx.getAuthor().getAsTag() + ": " + fReason).queue(
            nothing -> {
                ModerationUtils.modLog(ctx.getAuthor(), toBan, "kicked", fReason, ctx.getGuild());
                MessageUtils.sendSuccess(ctx.getMessage());
                ctx.getGuild().unban(toBan.getId())
                    .reason("(softban) Kicked by: " + ctx.getAuthor().getAsTag()).queue();
            }
        );
    }
    catch (HierarchyException ignored) {
        sendMsg(ctx, "I can't ban that member because his roles are above or equals to mine.");
    }
}
 
Example 4
Source Project: JDA   Source File: GuildImpl.java    License: Apache License 2.0 4 votes vote down vote up
protected void checkPosition(Member member)
{
    if(!getSelfMember().canInteract(member))
        throw new HierarchyException("Can't modify a member with higher or equal highest role than yourself!");
}
 
Example 5
Source Project: JDA   Source File: GuildImpl.java    License: Apache License 2.0 4 votes vote down vote up
protected void checkPosition(Role role)
{
    if(!getSelfMember().canInteract(role))
        throw new HierarchyException("Can't modify a role with higher or equal highest role than yourself! Role: " + role.toString());
}