java 使用createGuild()访问公会

nhhxz33t  于 2023-02-28  发布在  Java
关注(0)|答案(1)|浏览(126)

我想做一个函数,如果我输入!makeserver,让机器人创建一个公会并发送邀请链接给我。但是,guild.getSystemChannel()在回调中不起作用。我的JDA版本是4.4.0_352。

if (message[0].equalsIgnoreCase("!makeserver")) {
            if (message.length < 2) {
                event.getChannel().sendMessage("Name the server!").queue();
                return;
            }
            String serverName = message[1];
            event.getJDA().createGuild(serverName).queue(guild -> {
                GuildChannel defaultChannel = guild.getSystemChannel();// this code didn't work 
                defaultChannel.createInvite().queue(invite -> {
                    String inviteUrl = invite.getUrl();
                    event.getChannel().sendMessage("I made the server and send the link!\n" + inviteUrl).queue();
                }, error -> {
                    event.getChannel().sendMessage("Fail to send link.").queue();
                    if (error instanceof Exception) {
                        Exception e = (Exception) error;
                        e.printStackTrace();
                    }
                });
            }, error -> {
                event.getChannel().sendMessage("Fail to make the server .").queue();
                if (error instanceof Exception) {
                    Exception e = (Exception) error;
                    e.printStackTrace();
                }
            });
        }
    }
}

相关问题