英文:
Giving roles in JDA
问题
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().addRoleToMember(member, role).complete();
}
}
}
英文:
trying to make a JDA that gives roles on discord, however whenever i use getController() it puts a red line under it and there doesn't seem to be any libraries for ir , how else can i give a role, this is the code :
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
得分: 2
你必须使用Guild#addRoleToMember:
Guild guild = event.getGuild();
Role role = guild.getRoleById(roleId);
Member member = guild.getMemberById(userId);
guild.addRoleToMember(member, role).queue();
英文:
You have to use Guild#addRoleToMember:
Guild guild = event.getGuild();
Role role = guild.getRoleById(roleId);
Member member = guild.getMemberById(userId);
guild.addRoleToMember(member, role).queue();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论