Member.kick()什么也不做(Java上的Discord机器人)

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

Member.kick() does nothing (Discord bot on java)

问题

Main

List<Member> banned = new ArrayList<>();
public static void main(String[] args) throws LoginException {
    builder = new JDABuilder(AccountType.BOT);
    String token = "censored";
    builder.setToken(token);
    builder.addEventListeners(new Main());
    List<GatewayIntent> intents = new ArrayList<>();
    intents.add(GatewayIntent.GUILD_BANS);
    intents.add(GatewayIntent.GUILD_MEMBERS);
    builder.enableIntents(intents);
    builder.build();
}

not working part

if (event.getGuild().getSelfMember().hasPermission(Permission.KICK_MEMBERS)) {
    say(event.getChannel(), target.getEffectiveName() + " gekickt!");
} else {
    System.out.println("no permission");
}
if (event.getGuild().getSelfMember().hasPermission(Permission.KICK_MEMBERS)) {
    System.out.println("has permission");
}
if (!banned.contains(target)) {
    banned.add(target);
}
System.out.println("test3453");

event.getGuild().kick(target);
英文:

Main

    List&lt;Member&gt; banned=new ArrayList&lt;&gt;(); 
public static void main(String[] args) throws LoginException { 
builder=new JDABuilder(AccountType.BOT); 
String token=&quot;censored&quot;; 
builder.setToken(token); 
builder.addEventListeners(new Main());
 List&lt;GatewayIntent&gt; intents=new ArrayList&lt;&gt;(); 
intents.add(GatewayIntent.GUILD_BANS);
 intents.add(GatewayIntent.GUILD_MEMBERS); 
builder.enableIntents(intents); 
builder.build(); }

not working part

if(event.getGuild().getSelfMember().hasPermission(Permission.KICK_MEMBERS))
                           say(event.getChannel(),target.getEffectiveName()+&quot; gekickt!&quot;);
                           else
                               System.out.println(&quot;no permission&quot;);
                           if(event.getGuild().getSelfMember().hasPermission(Permission.KICK_MEMBERS))
                               System.out.println(&quot;has permission&quot;);
                           if(!banned.contains(target))
                           banned.add(target);
                           System.out.println(&quot;test3453&quot;);
    
                            event.getGuild().kick(target);

in the 2nd code part the bot should kick an User. In my console I see it has the permission to do so, but It doesnt kick anyone and I dont even get an error message.
Id be thankful if someone has ideas what I could have done wrong.

答案1

得分: 0

kick返回一个RestAction,这意味着您需要在其上调用.queue()。例如:member.kick().queue();

另请参阅:

英文:

kick returns a RestAction which means you have to call .queue() on it. For instance: member.kick().queue();

See also:

huangapple
  • 本文由 发表于 2020年8月28日 02:51:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/63622468.html
匿名

发表评论

匿名网友

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

确定