Search code examples
javaminecraftbukkitdiscord-jda

JDA returing null when getting guild by id


I am making Minecraft plugin, that will communicate with discord but when I try to get guild by id, it will return null.

jda = new JDABuilder(AccountType.BOT).setToken(token).build();
jda.addEventListener(new ReactionRecieveEvent(this));
jda.addEventListener(new CreateNewVoiceChannel(this));
jda.addEventListener(new DeleteEmptyChannel(this));
new VerifyCommand(this);

This is where I build JDA. Class VerifyCommand is command executor and I am trying to get the guild from it.


Solution

  • That way is deprecated, so use this way.

    jda = JDABuilder.createDefault(token).build();
    jda.addEventListener(new ReactionRecieveEvent(this));
    jda.addEventListener(new CreateNewVoiceChannel(this));
    jda.addEventListener(new DeleteEmptyChannel(this));
    new VerifyCommand(this);
    

    or you can use this way to improve readability

    jda = JDABuilder.createDefault(token)
        .addEventListener(new ReactionRecieveEvent(this))
        .addEventListener(new CreateNewVoiceChannel(this))
        .addEventListener(new DeleteEmptyChannel(this))
        .build();
    new VerifyCommand(this);
    

    You can see wiki for simple questions https://github.com/DV8FromTheWorld/JDA/wiki