英文:
JDA member.ban(); Doesn't Ban the member?
问题
我在使用JDA 4中的member.ban()时遇到了问题;当我调用这个命令时,它没有在控制台输出任何错误,它只输出如下信息:
> 成功封禁 MB:[昵称](U:[用户名 [用户ID]) / G:[服务器名称] [服务器ID]))
以下是运行这段代码的代码:
@Override
public void onGuildMessageReceived(GuildMessageReceivedEvent event){
String[] args = event.getMessage().getContentRaw().split("\\s+");
if(args[0].equalsIgnoreCase(cogBotMain.prefix + "Ban") && event.getMember().hasPermission(Permission.BAN_MEMBERS)){
Member member = event.getGuild().getMemberById(args[1].replace("<@!", "").replace(">", ""));
if(args.length < 3){
//ERROR
EmbedBuilder errorban = new EmbedBuilder();
errorban.setTitle("Cog Bot - 语法错误");
errorban.setDescription("请使用正确的语法:" + cogBotMain.prefix + "ban <提及用户> <要删除的消息数量> <原因>");
errorban.setColor(0xf56e6e);
errorban.setFooter("由 A Yoshi#1662 创建");
event.getChannel().sendMessage(errorban.build()).complete();
errorban.clear();
}else{
String Banres = args[3];
int BanTime = Integer.parseInt(args[2]);
if (member != null) {
member.ban(BanTime,Banres);
event.getChannel().sendMessage("成功封禁 " + member).complete();
}
}
}
}
希望这能帮助你解决问题。
英文:
I am having trouble with using member.ban() in JDA 4; when I call the cmd it doesn't send any error to console all it outputs is
> Successfully banned MB:[nicknamehere](U:[usernamehere [usersidhere]) / G:[GuildNameHere] [GuildIDHere))
This is the code that runs this
public void onGuildMessageReceived(GuildMessageReceivedEvent event){
String[] args = event.getMessage().getContentRaw().split("\\s+");
if(args[0].equalsIgnoreCase(cogBotMain.prefix + "Ban") && event.getMember().hasPermission(Permission.BAN_MEMBERS)){
Member member = event.getGuild().getMemberById(args[1].replace("<@!", "").replace(">", ""));
if(args.length < 3){
//ERROR
EmbedBuilder errorban = new EmbedBuilder();
errorban.setTitle("Cog Bot - Syntax Error");
errorban.setDescription("Please use the proper syntax: " + cogBotMain.prefix + "ban <mentionTheUser> <NumberMessagesToDelete> <Reason>");
errorban.setColor(0xf56e6e);
errorban.setFooter("Created by A Yoshi#1662");
event.getChannel().sendMessage(errorban.build()).complete();
errorban.clear();
}else{
String Banres = args[3];
int BanTime = Integer.parseInt(args[2]);
if (member != null) {
member.ban(BanTime,Banres);
event.getChannel().sendMessage("Successfully banned " + member).complete();
}
}
}
}
</details>
# 答案1
**得分**: 1
你忘记在 `member.ban(BanTime,Banres);` 后面加上 `queue()`。
<details>
<summary>英文:</summary>
Hey you forgot the `queue()` behind the `member.ban(BanTime,Banres);`
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论