Jda: Message sends twice

Created on 17 Mar 2017  路  6Comments  路  Source: DV8FromTheWorld/JDA

Hey,

Whenever I use something like

if (event.isFromType(ChannelType.PRIVATE)) //If this message was sent to a PrivateChannel
        {
            //The message was sent in a PrivateChannel.
            //In this example we don't directly use the privateChannel, however, be sure, there are uses for it!
            PrivateChannel privateChannel = event.getPrivateChannel();

            System.out.printf("[PRIV]<%s>: %s\n", author.getName(), msg);
            privateChannel.sendMessage("This message should only be sent once").queue();
}

And then I send the bot a message, it sends back mutliple times. Let me demonstrate: https://gyazo.com/3cf013f9330b9f1a4190a85ed86e46e0

Any idea why this might be happening? Using your exact example 馃挴

Most helpful comment

The bot gets an event for its own message.

All 6 comments

The bot gets an event for its own message.

So, basically, to fix, check if the message is received from a client or is there an own event to recieve message from clients only?

just compare the author to the selfuser

Thanks! You may close the issue if i can't do it myself.

If you need more assistance, please ask in the #java_jda channel

You should check whether the message author is the currently logged in account.
event.getMessage().getAuthor().equals(event.getJDA().getSelfUser())
It is also good practice to ignore messages from Users that are bot accounts User#isBot()

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Frederikam picture Frederikam  路  4Comments

AutismSpeaks picture AutismSpeaks  路  4Comments

M4itreG picture M4itreG  路  5Comments

sachinhasaphatass picture sachinhasaphatass  路  3Comments

Frederikam picture Frederikam  路  3Comments