question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sendMessage in onPrivateMessageReceived causes message spamming.

See original GitHub issue

First let me say i picked up this API around midnight last night and thanks to its ease of use i had a working bot in 5 hours. Thanks for making this.

Now for the issue. It was rather random so therefore i have no idea what could be causing it, but essentially when sendMessage is called in onPrivateMessageReceived (as well as onMessageRecieved with isPrivate check), it causes the bot to spam the message infinitley until the ‘TOO MUCH TOO FAST’ exception is thrown.

At first i was thinking it was an error in my code, but after commenting literally everything that isnt just the main startup and the onPrivateMessageReceived event, ive come to the conclusion that it is something to do with JDA.

This is pretty much the program after all the commenting

The imports

import net.dv8tion.jda.JDABuilder; import net.dv8tion.jda.entities.; import net.dv8tion.jda.entities.Guild; import net.dv8tion.jda.events.ReadyEvent; import net.dv8tion.jda.events.audio.; import net.dv8tion.jda.events.DisconnectEvent; import net.dv8tion.jda.events.ReconnectedEvent; import net.dv8tion.jda.events.message.priv.PrivateMessageReceivedEvent; import net.dv8tion.jda.events.message.MessageReceivedEvent; import net.dv8tion.jda.hooks.ListenerAdapter; import net.dv8tion.jda.audio.player.FilePlayer; import net.dv8tion.jda.audio.player.Player;

import javax.security.auth.login.LoginException; import javax.sound.sampled.UnsupportedAudioFileException; import java.io.File; import java.io.IOException; import java.util.List; import java.util.Random; import java.util.concurrent.TimeUnit;

public static void main(String[] args)
{
    try {
        new JDABuilder().setBotToken(m_botToken).addListener(new highNoonBot()).buildBlocking();
    }
    catch (IllegalArgumentException e) {
        System.out.println("ERROR: No token entered, fix it.");
    }
    catch (LoginException e) {
        System.out.println("ERROR: The token entered is invalid, fix it.");
    }
    catch (InterruptedException e) {
        e.printStackTrace();
    }
}

@Override
public void onPrivateMessageReceived(PrivateMessageReceivedEvent event) {
    event.getChannel().sendMessage("Test");
    return;
}

The main is pretty much pure copy and paste from your examples and the on onPrivateMessageReceived just does the sendMessage, but when you message the bot you get this.

http://puu.sh/oSehN/dde45f3700.png

Here is the console log up to the point of the exception

[21:25:13] [Info] [JDAAudioManager]: Audio System successfully setup! [21:25:13] [Info] [JDA]: JDA starting... [21:25:14] [Info] [JDA]: Login Successful! [21:25:14] [Info] [JDASocket]: Connected to WebSocket [21:25:15] [Info] [JDA]: Finished Loading! [21:25:20] [Fatal] [JDA]: One of the EventListeners had an uncaught exception [21:25:20] [Fatal] [JDA]: Encountered an exception: net.dv8tion.jda.exceptions.RateLimitedException: The message got Rate-Limited. You are able to send messages again in 4589 ms at net.dv8tion.jda.entities.impl.PrivateChannelImpl.sendMessage(PrivateChannelImpl.java:88) at net.dv8tion.jda.entities.impl.PrivateChannelImpl.sendMessage(PrivateChannelImpl.java:70) at its.high.noon.highNoonBot.onPrivateMessageReceived(highNoonBot.java:180) at net.dv8tion.jda.hooks.ListenerAdapter.onEvent(ListenerAdapter.java:167) at net.dv8tion.jda.hooks.InterfacedEventManager.handle(InterfacedEventManager.java:57) at net.dv8tion.jda.handle.MessageReceivedHandler.handleInternally(MessageReceivedHandler.java:59) at net.dv8tion.jda.handle.SocketHandler.handle(SocketHandler.java:36) at net.dv8tion.jda.requests.WebSocketClient.handleEvent(WebSocketClient.java:545) at net.dv8tion.jda.requests.WebSocketClient.onTextMessage(WebSocketClient.java:296) at com.neovisionaries.ws.client.ListenerManager.callOnTextMessage(ListenerManager.java:352) at com.neovisionaries.ws.client.ReadingThread.callOnTextMessage(ReadingThread.java:233) at com.neovisionaries.ws.client.ReadingThread.callOnTextMessage(ReadingThread.java:211) at com.neovisionaries.ws.client.ReadingThread.handleTextFrame(ReadingThread.java:910) at com.neovisionaries.ws.client.ReadingThread.handleFrame(ReadingThread.java:693) at com.neovisionaries.ws.client.ReadingThread.main(ReadingThread.java:102) at com.neovisionaries.ws.client.ReadingThread.run(ReadingThread.java:61)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
DV8FromTheWorldcommented, Nov 28, 2016

So if you don’t want the bot to respond to itself, you need to add a check for that.

0reactions
Somebodyisnobodycommented, Jan 20, 2021

That works perfectly, thank you! For the rest searching how to solve this:

PrivateMessageReceivedEvent event;

if ( event.getAuthor().getIdLong() != event.getJDA().getSelfUser().getIdLong() ) {
    send a message
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

i have a problem with my bot (spamming messages)
Every time the bot sends a message, the client.on('messageCreate') event listener runs, because a message has been posted which leads to an ...
Read more >
Email Error 550: High Probability of Spam - Warmup Inbox
A 550 Spam error is a catchall error message that is relayed back to the user within a bounced message to alert them...
Read more >
discord-anti-spam.js - npm
Start using discord-anti-spam in your project by running `npm i discord-anti-spam`. ... Example of a basic bot handling spam messages using this module....
Read more >
Report a message that you receive on Instagram
1. Go to the conversation. ; 2. Tap in the top right. ; 3. Tap Report. Note: You will not see this option...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found