在JDA中扮演角色

时间:2020-05-28 22:45:43

标签: java discord discord-jda

试图制作一个JDA,它在不一致时赋予角色,但是,每当我使用getController()时,它都会在下面加上一条红线,并且似乎没有ir的任何库,我还能如何赋予这个角色,这是代码:

    if(args[0].equalsIgnoreCase(Main.prefix + "mute")){

        if (args.length == 2) {
            Member member = event.getGuild().getMemberById(args[1].replace("<@", "").replace(">", ""));
            Role role = event.getGuild().getRoleById("715670284023365824");

            if (!member.getRoles().contains(role)) {
                //Mute user
                event.getChannel().sendMessage("Muted " + args[1]).queue();
                event.getGuild().getController().addRolesToMember(member, role).complete();
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

您必须使用Guild#addRoleToMember

Guild guild = event.getGuild();
Role role = guild.getRoleById(roleId);
Member member = guild.getMemberById(userId);
guild.addRoleToMember(member, role).queue();