英文:
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<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);
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:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论