Costin Teodor
Costin Teodor

Reputation: 37

Java Discord Bot event.getMessage().getContentRaw() is empty

I am following a guide on how to create a discord bot in Java, but no matter what I do, the bot cannot take messages from server. It knows that they have been sent, but cannot get their content.

I've tried getContentRaw(), getcontentDisplayed(), getContentStripped() methods, but none of them return anything but an empty string.

public static void main(String[] args) {
    JDA jda = JDABuilder.createDefault(token)
            .setActivity(Activity.playing("something"))
            .enableIntents(GatewayIntent.GUILD_MESSAGES)
            .enableIntents(GatewayIntent.DIRECT_MESSAGES)
            .addEventListeners(new DiscordBot())
            .build();
}


@Override
public void onMessageReceived(@NotNull MessageReceivedEvent event) {
    System.out.println(event.getMessage().getContentRaw());
    System.out.println(event.getAuthor().getName());

}

I can see the author in the console.

I also tried with different versions of the dependency, but what I've tried return same empty string. I gave the bot administrator permissions (I don't wish to publish it, I am just creating it for fun), but it still doesn't work.

I tried to use enableIntents(GatewayIntent.MESSAGE_CONTENT) method in the builder, but the program immediately stops with error code 0

Upvotes: 1

Views: 962

Answers (2)

Kaktus
Kaktus

Reputation: 1

Thanks this was really bugging me lmao

Upvotes: 0

CarlosDiamon
CarlosDiamon

Reputation: 36

You did not add this: GatewayIntent.MESSAGE_CONTENT [enter image description here][1] Discord if I'm not wrong recently added that without this option does not leave the message so, if you try tageando the bot will be shown, yesterday I spent the same thing but researching found the solution

(1) make sure to activate the corresponding inits in the discord developers portal [1]: https://i.sstatic.net/8VMRv.png

(2) add this to your code [2]:

 JDA jda = JDABuilder.createDefault(token)
            .setActivity(Activity.playing("something"))
            .enableIntents(GatewayIntent.MESSAGE_CONTENT)
            .addEventListeners(new DiscordBot())
            .build();

Upvotes: 2

Related Questions