JDA member.ban(); 不会封禁该成员吗?

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

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(&quot;\\s+&quot;);

        if(args[0].equalsIgnoreCase(cogBotMain.prefix + &quot;Ban&quot;) &amp;&amp; event.getMember().hasPermission(Permission.BAN_MEMBERS)){
            Member member = event.getGuild().getMemberById(args[1].replace(&quot;&lt;@!&quot;, &quot;&quot;).replace(&quot;&gt;&quot;, &quot;&quot;));
            if(args.length &lt; 3){
                //ERROR
                EmbedBuilder errorban = new EmbedBuilder();
                errorban.setTitle(&quot;Cog Bot - Syntax Error&quot;);
                errorban.setDescription(&quot;Please use the proper syntax: &quot; + cogBotMain.prefix + &quot;ban &lt;mentionTheUser&gt; &lt;NumberMessagesToDelete&gt; &lt;Reason&gt;&quot;);
                errorban.setColor(0xf56e6e);
                errorban.setFooter(&quot;Created by A Yoshi#1662&quot;);

                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(&quot;Successfully banned &quot; + 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>



huangapple
  • 本文由 发表于 2020年7月31日 04:23:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/63180843.html
匿名

发表评论

匿名网友

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

确定