Dsyt
Dsyt

Reputation: 3

Access guild with createGuild()

I want to make a function that makes the bot create a guild and send me the invite link, if I type !makeserver. However, guild.getSystemChannel() does not work in the callback. My JDA version is 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();
                }
            });
        }
    }
}

Upvotes: 0

Views: 63

Answers (1)

Minn
Minn

Reputation: 6131

The callback does not provide the guild, you need to use the GuildJoinEvent instead.

Upvotes: 0

Related Questions