在JDA中分配角色。

huangapple go评论92阅读模式
英文:

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 + &quot;mute&quot;)){
		
		if (args.length == 2) {
			Member member = event.getGuild().getMemberById(args[1].replace(&quot;&lt;@&quot;, &quot;&quot;).replace(&quot;&gt;&quot;, &quot;&quot;));
			Role role = event.getGuild().getRoleById(&quot;715670284023365824&quot;);
			
			if (!member.getRoles().contains(role)) {
				//Mute user
				event.getChannel().sendMessage(&quot;Muted &quot; + 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();

huangapple
  • 本文由 发表于 2020年5月29日 06:45:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/62075761.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定