当前位置: 首页>>代码示例>>Java>>正文


Java Guild.getRolesByName方法代码示例

本文整理汇总了Java中net.dv8tion.jda.core.entities.Guild.getRolesByName方法的典型用法代码示例。如果您正苦于以下问题:Java Guild.getRolesByName方法的具体用法?Java Guild.getRolesByName怎么用?Java Guild.getRolesByName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.dv8tion.jda.core.entities.Guild的用法示例。


在下文中一共展示了Guild.getRolesByName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findRole

import net.dv8tion.jda.core.entities.Guild; //导入方法依赖的package包/类
public static Role findRole(Guild guild, String name) {
    List<Role> roles = guild.getRolesByName(RoleManager.SUPPORT_ROLE_NAME, true);

    if (roles.size() <= 0) {
        throw new RuntimeException("Role with name " + name + " on Guild " + guild.getName() + " not found!");
    } else {
        return roles.get(0);
    }
}
 
开发者ID:michidk,项目名称:GGD-Discord-Bot,代码行数:10,代码来源:RoleManager.java

示例2: setDiscordRank

import net.dv8tion.jda.core.entities.Guild; //导入方法依赖的package包/类
/**
 * Set the Discord rank of a player. If the bot doesn't find the rank in the Discord Guild or can't set the rank, nothing happens.
 * @param user The user to set the rank to.
 * @param guild The guild we want to set the rank in
 * @param rank The rank we want to set.
 */
public void setDiscordRank(User user, Guild guild, String rank) {
    if (rank == null) {
        return;
    }
    List<Role> botRole = guild.getMember(getBot().getJDA(guild).getSelfUser()).getRoles();
    final int[] botRoleRank = {-999};
    botRole.forEach(r -> {
        if (r.getPosition() > botRoleRank[0]) {
            botRoleRank[0] = r.getPosition();
        }
    });

    List<Role> rolesToAdd = guild.getRolesByName(rank, true);
    if (rolesToAdd.isEmpty()) {
        return;
    }

    if (rolesToAdd.get(0).getPosition() > botRoleRank[0]) {
        return; //Can't set a rank higher than us.
    }


    //We try to load all the other ranks so we do a cleanup at the same time.
    Set<String> allRanks = new HashSet<>();
    GuildSettings settings = getBot().getGuildSettings(guild);
    for(int i = 0; i <= 9; i++) {
        String entry = settings.getSetting(SETTING_RANK_PREFIX + i);
        if (entry != null) {
            allRanks.add(entry);
        }
    }
    if (allRanks.contains(rank)) {
        allRanks.remove(rank);
    }

    List<Role> rolesToRemove = new ArrayList<>();
    List<Role> memberRoles = guild.getMember(user).getRoles();
    for(String rankEntry: allRanks) {
        List<Role> roles = guild.getRolesByName(rankEntry, false);
        if (!roles.isEmpty()){
            if (memberRoles.contains(roles.get(0))) {
                if (roles.get(0).getPosition() < botRoleRank[0]) {
                    rolesToRemove.add(roles.get(0));
                } else {
                    log.info("The bot can't remove rank " + rankEntry + " on user " + user.getName());
                }
            } else {
                log.info("Role " + rankEntry + " not on user" + user.getName());
            }

        } else {
            log.info("Role " + rankEntry + " not found!");
        }
    }



    try {
        guild.getController().modifyMemberRoles(guild.getMember(user), rolesToAdd, rolesToRemove).reason("LegendaryBot - Rank Sync with WoW Guild.").queue();
        log.info("User " + user.getName());
        log.info("Adding ranks:");
        rolesToAdd.forEach(v -> log.info(v.getName()));
        log.info("Removing ranks:");
        rolesToRemove.forEach(v -> log.info(v.getName()));
    } catch (PermissionException e) {
        e.printStackTrace();
        getBot().getStacktraceHandler().sendStacktrace(e);
    }

}
 
开发者ID:greatman,项目名称:legendarybot,代码行数:77,代码来源:WoWLinkPlugin.java


注:本文中的net.dv8tion.jda.core.entities.Guild.getRolesByName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。