Java Code Examples for net.dv8tion.jda.api.Permission#MANAGE_ROLES

The following examples show how to use net.dv8tion.jda.api.Permission#MANAGE_ROLES . 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 File: UnmuteCommand.java    From SkyBot with GNU Affero General Public License v3.0 6 votes vote down vote up
public UnmuteCommand() {
    this.shouldLoadMembers = true;
    this.requiresArgs = true;
    this.name = "unmute";
    this.help = "Removes the mute of a user if they are muted";
    this.usage = "<@user> [-r reason]";
    this.botPermissions = new Permission[]{
        Permission.MANAGE_SERVER,
        Permission.MANAGE_ROLES,
    };
    this.flags = new Flag[]{
        new Flag(
            'r',
            "reason",
            "Sets the reason for this umnute"
        ),
    };
}
 
Example 2
Source File: TempMuteCommand.java    From SkyBot with GNU Affero General Public License v3.0 6 votes vote down vote up
public TempMuteCommand() {
    this.shouldLoadMembers = true;
    this.requiresArgs = true;
    this.requiredArgCount = 2;
    this.name = "tempmute";
    this.help = "Temporally mutes a user in the server, this will override any existing tempmutes for the user";
    this.usage = "<@user> <time><w/d/h/m/s> [-r reason]";
    this.botPermissions = new Permission[]{
        Permission.MANAGE_SERVER,
        Permission.MANAGE_ROLES,
    };
    this.flags = new Flag[]{
        new Flag(
            'r',
            "reason",
            "Sets the reason for this mute"
        ),
    };
}
 
Example 3
Source File: MuteCommand.java    From SkyBot with GNU Affero General Public License v3.0 6 votes vote down vote up
public MuteCommand() {
    this.shouldLoadMembers = true;
    this.requiresArgs = true;
    this.name = "mute";
    this.help = "Mutes a user in the server";
    this.usage = "<@user> [-r reason]";
    this.botPermissions = new Permission[]{
        Permission.MANAGE_SERVER,
        Permission.MANAGE_ROLES,
    };
    this.flags = new Flag[]{
        new Flag(
            'r',
            "reason",
            "Sets the reason for this mute"
        ),
    };
}
 
Example 4
Source File: RoleManagerImpl.java    From JDA with 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 5
Source File: RoleImpl.java    From JDA with 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 6
Source File: RoleOrderActionImpl.java    From JDA with Apache License 2.0 5 votes vote down vote up
@Override
protected RequestBody finalizeData()
{
    final Member self = guild.getSelfMember();
    final boolean isOwner = self.isOwner();

    if (!isOwner)
    {
        if (self.getRoles().isEmpty())
            throw new IllegalStateException("Cannot move roles above your highest role unless you are the guild owner");
        if (!self.hasPermission(Permission.MANAGE_ROLES))
            throw new InsufficientPermissionException(guild, Permission.MANAGE_ROLES);
    }

    DataArray array = DataArray.empty();
    List<Role> ordering = new ArrayList<>(orderList);

    //If not in normal discord order, reverse.
    // Normal order is descending, not ascending.
    if (ascendingOrder)
        Collections.reverse(ordering);

    for (int i = 0; i < ordering.size(); i++)
    {
        Role role = ordering.get(i);
        final int initialPos = role.getPosition();
        if (initialPos != i && !isOwner && !self.canInteract(role))
            // If the current role was moved, we are not owner and we can't interact with the role then throw a PermissionException
            throw new IllegalStateException("Cannot change order: One of the roles could not be moved due to hierarchical power!");

        array.add(DataObject.empty()
                .put("id", role.getId())
                .put("position", i + 1)); //plus 1 because position 0 is the @everyone position.
    }

    return getRequestBody(array);
}