sendMessage in onPrivateMessageReceived causes message spamming.
See original GitHub issueFirst 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:
- Created 7 years ago
- Comments:9 (3 by maintainers)
Top GitHub Comments
So if you don’t want the bot to respond to itself, you need to add a check for that.
That works perfectly, thank you! For the rest searching how to solve this: