discord-jda / jda Goto Github PK
View Code? Open in Web Editor NEWJava wrapper for the popular chat & VOIP service: Discord https://discord.com
License: Apache License 2.0
Java wrapper for the popular chat & VOIP service: Discord https://discord.com
License: Apache License 2.0
Message from the API (is this just an error log?):
I have removed the json because it contains information from my server. I don't know what response is this that you are logging for this error. If you need it in order to fix, tell me.
Got an unexpected Json-parse error. Please redirect following message to the devs:
JSONObject["muted_channels"] not found.
READY -> {"user_settings":{"inline_embed_media":true,"render_embeds":true,"inline_attachment_media":true,"show_current_game":true,"theme":"dark","enable_tts_command":true,"locale":"pt-BR","convert_emoticons":true,"message_display_compact":true},"read_state": ...
When I trying to send a bit long message (http://pastebin.com/3J9iD3Dq) it simply doesn't sending, if i remove the logest line it works perfectly, but adding \n in middle doesn't help.
Method call:
reply(msg, "Комманды:\n" + FormatUtils.foramtHelp());
(FormatUtils.formateHelp() return the message i gave link before)
Methods:
public static void reply(Message orig, String reply) { reply(orig.getChannel(), orig.getAuthor(), reply); }
public static void reply(MessageChannel cn, User sender, String text) { sendMessage(cn, new MessageBuilder().appendMention(sender).appendString(" " + text).build()); }
public static void sendMessage(MessageChannel cn, Message msg) { cn.sendMessage(msg); }
I'm getting this exception sometimes when someone requests my music bot to join a voice channel:
[21:31:55] [Fatal] [JDASocket]: Encountered an exception:
[21:31:55] [Fatal] [JDASocket]: java.lang.RuntimeException: com.neovisionaries.ws.client.WebSocketException: Failed to send an opening handshake request to the server: Connection reset
at net.dv8tion.jda.audio.AudioWebSocket.<init>(AudioWebSocket.java:109)
at net.dv8tion.jda.handle.VoiceServerUpdateHandler.handleInternally(VoiceServerUpdateHandler.java:68)
at net.dv8tion.jda.handle.SocketHandler.handle(SocketHandler.java:38)
at net.dv8tion.jda.requests.WebSocketClient.handleEvent(WebSocketClient.java:615)
at net.dv8tion.jda.requests.WebSocketClient.onTextMessage(WebSocketClient.java:324)
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)
Caused by: com.neovisionaries.ws.client.WebSocketException: Failed to send an opening handshake request to the server: Connection reset
at com.neovisionaries.ws.client.WebSocket.writeHandshake(WebSocket.java:2546)
at com.neovisionaries.ws.client.WebSocket.shakeHands(WebSocket.java:2437)
at com.neovisionaries.ws.client.WebSocket.connect(WebSocket.java:1583)
at net.dv8tion.jda.audio.AudioWebSocket.<init>(AudioWebSocket.java:104)
... 11 more
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:209)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
at sun.security.ssl.InputRecord.read(InputRecord.java:503)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:747)
at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:123)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
at java.io.FilterOutputStream.flush(FilterOutputStream.java:140)
at com.neovisionaries.ws.client.WebSocket.writeHandshake(WebSocket.java:2539)
... 14 more
As a result of this the bot doesn't actually connect to the voice channel, but the audio manager will still think it is trying to connect to the voice channel, since it throws this exception the second time:
java.lang.IllegalStateException: Already attempting to start an AudioConnection with a VoiceChannel!
Currently Attempting Channel ID: 99619915127848960 | New Attempt Channel ID: 99619915127848960
net.dv8tion.jda.managers.impl.AudioManagerImpl.openAudioConnection(AudioManagerImpl.java:71)
fredboat.audio.GuildPlayer.joinChannel(GuildPlayer.java:70)
fredboat.audio.GuildPlayer.joinChannel(GuildPlayer.java:47)
fredboat.command.music.JoinCommand.onInvoke(JoinCommand.java:17)
fredboat.commandmeta.CommandManager.prefixCalled(CommandManager.java:39)
I have also noticed that sometimes the bot will appear to be connected to a voice channel on the client but is unable to play audio or closing the connection with AudioManager.closeAudioConnection()
, having no effect at all. In this case trying to connect to the voice channel results in the same IllegalStateException
.
Restarting the bot seems to be the only temporary fix, as kicking and reinviting the bot will not fix it.
It might be that the WebSocketException
is only triggered after the bug has first occurred and the bot is reinvited.
This has been going on for several versions now. The bot is currently running JDA 2.2.1_355
.
Hello, I've been using your library for my own project, but with the new Applications migration I'm left wondering how to authenticate my bot now since there is no password. Could you provide a complete example of how to initialize a bot under this new system? Thank you.
Can't use EventListener and ListenerAdapter at the same time. JDA forces itself to just use EventListener. It should at least throw an exception instead of being silently quiet.
public class DiscordBotMain {
public static void main(String[] args) {
JDA jda = new JDABuilder().setBotToken(###).buildBlocking();
jda.addEventListener(new DiscordBot());
}
}
public class DiscordBot extends ListenerAdapter implements EventListener {
@Override
public void onMessageReceived(MessageReceivedEvent event)
{
System.out.println("Message");
}
@Override
public void onEvent(Event event)
{
System.out.println("Event!");
}
}
Currently if a user is not known (specifically in Guilds) EntityBuilder#createMessage will throw an IllegalArgumentException (for Group and TextChannel).
This should not happen since it is possible that Messages exist with an actual user that is not contained in the local cache. However the usual Message JSON provided by discord does contain information with which we can build a fake User (just like we do for WebHook Messages)!
It looks like my music bot got disconnected from the web socket, so it attempted to reconnect. However, when it does reconnect it throws this IllegalStateException
and it disconnects. It looks like this in the log:
[17:08:19] [Warning] [JDASocket]: Got disconnected from WebSocket (Internet?!)... Attempting to reconnect in 2s
[17:08:21] [Warning] [JDASocket]: Attempting to reconnect!
[17:08:22] [Info] [JDASocket]: Connected to WebSocket
[17:08:22] [Fatal] [JDASocket]: Encountered an exception:
[17:08:22] [Fatal] [JDASocket]: java.lang.IllegalStateException: Already attempting to start an AudioConnection with a VoiceChannel!
Currently Attempting Channel ID: 204878762926407681 | New Attempt Channel ID: 204878762926407681
at net.dv8tion.jda.managers.impl.AudioManagerImpl.openAudioConnection(AudioManagerImpl.java:71)
at net.dv8tion.jda.requests.WebSocketClient.reconnectAudioConnections(WebSocketClient.java:535)
at net.dv8tion.jda.requests.WebSocketClient.ready(WebSocketClient.java:133)
at net.dv8tion.jda.requests.WebSocketClient.handleEvent(WebSocketClient.java:584)
at net.dv8tion.jda.requests.WebSocketClient.onTextMessage(WebSocketClient.java:324)
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)
[17:08:22] [Warning] [JDASocket]: Got disconnected from WebSocket (Internet?!)... Attempting to reconnect in 2s
[17:08:24] [Warning] [JDASocket]: Attempting to reconnect!
[17:08:25] [Info] [JDASocket]: Connected to WebSocket
[etc]
This cycle would then repeat until I terminated my bot, but it was unusable until then. This is possibly related to #110.
How would i go about getting an inputstream from the audio in a voice channel
I'm working on a small, silly project in Eclipse on Windows 8.1, 64-bit. I've been using JDK 1.8.0_20 and JDA 1.2.2_139. My project is working fine in Eclipse, but when I try to pack and run it as a jar, I keep getting the same response:
Connecting to Discord...
Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Users\toders\AppDa
ta\Local\Temp\opus360617407824081820.dll: The process cannot access the file bec
ause it is being used by another process
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
at net.dv8tion.jda.utils.NativeUtils.loadLibraryFromJar(NativeUtils.java
:121)
at net.dv8tion.jda.managers.AudioManager.<clinit>(AudioManager.java:311)
at net.dv8tion.jda.entities.impl.JDAImpl.<init>(JDAImpl.java:62)
at net.dv8tion.jda.JDABuilder.buildAsync(JDABuilder.java:235)
at JohnCenaBot.<init>(JohnCenaBot.java:42)
at JohnCenaBot.main(JohnCenaBot.java:33)
(The exact numbers after opus
vary)
I am relatively new to creating jar files, so it's possible that I'm making a mistake, but I've tried this every way I can find and it still doesn't work. Using a Gradle command to pack all dependencies, referencing the library in the jar's manifest, using Eclipse to pack all referenced libraries. Once or twice it's run perfectly, but the next time it crashes again, with no changes to the files or commands. I started out with Gradle, but after a while I tried making a new, non-Gradle project and just linking to the "Dependencies Included" JDA jar. This does not appear to have had any effect on the outcome. Attached is my non-Gradle Eclipse project; it's really just one class and a sound file.
Edit by Kantenkugel: Removed token-file from zip-file
JohnCenaBot_noToken.zip
I am trying to start up my Discord bot on an Ubuntu 16.04 Server, and it cannot maintain a websocket apparently (as I've been told)
Here is the error associated with it
I am not sure if this has to do with something I am doing wrong or not...
Thanks!
I booted my bot today and it caught this error. To me, it looks like an error with JDA but I could be wrong. Could somebody confirm?
java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901)
at java.util.ArrayList$Itr.next(ArrayList.java:851)
at java.util.Collections$UnmodifiableCollection$1.next(Collections.java:1042)
at net.dv8tion.jda.utils.PermissionUtil.getEffectivePermission(PermissionUtil.java:215)
at net.dv8tion.jda.utils.PermissionUtil.getEffectivePermission(PermissionUtil.java:240)
at net.dv8tion.jda.utils.PermissionUtil.checkPermission(PermissionUtil.java:234)
at net.dv8tion.jda.utils.PermissionUtil.checkPermission(PermissionUtil.java:129)
at net.dv8tion.jda.entities.impl.TextChannelImpl.checkPermission(TextChannelImpl.java:289)
at net.dv8tion.jda.entities.impl.TextChannelImpl.sendMessageAsync(TextChannelImpl.java:208)
at net.dv8tion.jda.entities.impl.TextChannelImpl.sendMessageAsync(TextChannelImpl.java:200)
at com.erisbot.listeners.OtherListener.onReady(OtherListener.java:23)
at net.dv8tion.jda.hooks.ListenerAdapter.onEvent(ListenerAdapter.java:149)
at net.dv8tion.jda.hooks.InterfacedEventManager.handle(InterfacedEventManager.java:64)
at net.dv8tion.jda.requests.WebSocketClient.ready(WebSocketClient.java:120)
at net.dv8tion.jda.handle.ReadyHandler.finishReady(ReadyHandler.java:137)
at net.dv8tion.jda.handle.ReadyHandler.onGuildInit(ReadyHandler.java:122)
at net.dv8tion.jda.handle.GuildJoinHandler.lambda$handleInternally$45(GuildJoinHandler.java:44)
at net.dv8tion.jda.handle.EntityBuilder.createGuildFirstPass(EntityBuilder.java:213)
at net.dv8tion.jda.handle.GuildJoinHandler.handleInternally(GuildJoinHandler.java:38)
at net.dv8tion.jda.handle.SocketHandler.handle(SocketHandler.java:38)
at net.dv8tion.jda.requests.WebSocketClient.handleEvent(WebSocketClient.java:607)
at net.dv8tion.jda.requests.WebSocketClient.onTextMessage(WebSocketClient.java:315)
at net.dv8tion.jda.requests.WebSocketClient.onBinaryMessage(WebSocketClient.java:680)
at com.neovisionaries.ws.client.ListenerManager.callOnBinaryMessage(ListenerManager.java:368)
at com.neovisionaries.ws.client.ReadingThread.callOnBinaryMessage(ReadingThread.java:243)
at com.neovisionaries.ws.client.ReadingThread.handleBinaryFrame(ReadingThread.java:937)
at com.neovisionaries.ws.client.ReadingThread.handleFrame(ReadingThread.java:696)
at com.neovisionaries.ws.client.ReadingThread.main(ReadingThread.java:102)
at com.neovisionaries.ws.client.ReadingThread.run(ReadingThread.java:61)
VoiceStatus appears to only be correct for joins/changes/leaves made after the bot has connected.
Example Scenario:
Note: Might be related to #112
I noticed an issue where audio doesn't play at times, usually when it's the first time calling
player.play()
if I do player.stop(), load my file again, and then do player.play() again, audio plays fine for the rest of the player's usage.
If you need any more info, please let me know
I'm not sure if this is a design flaw or intended but when using the audio feature of the bot on multiple servers, it struggles to work out which is which. I'm able to control the music for 1 server from another. Is this intended?
When you move the position of a role in the hierarchy, the list returned by Member#getRoles() doesn't reorder the roles accordingly (although it does add the new Role, at the bottom of the list).
I discovered some huge spikes in my music bot that causes the program to run out of memory without exiting the process properly.
I obtained a memory dump from a crash I had while sleeping. Turns out that most of the memory usage comes from net.dv8tion.jda.requests.WebSocketClient. Here's a summary:
Here's a report I generated:
report378760232241.pdf
I can provide the memory dump if necessary.
Edit: I suspect this has to do with event caching
I tried using your audio example and it gave this error.
java.lang.NoSuchMethodError: org.tritonus.share.sampled.AudioUtils.millis2Frames(JF)J at org.tritonus.sampled.convert.SampleRateConversionProvider$SampleRateConverterStream.resizeBuffers(SampleRateConversionProvider.java:292) at org.tritonus.sampled.convert.SampleRateConversionProvider$SampleRateConverterStream.<init>(SampleRateConversionProvider.java:276) at org.tritonus.sampled.convert.SampleRateConversionProvider.getAudioInputStream(SampleRateConversionProvider.java:111) at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source) at net.dv8tion.jda.audio.player.Player.setAudioSource(Player.java:79) at net.dv8tion.jda.audio.player.FilePlayer.setAudioFile(FilePlayer.java:46) at net.dv8tion.jda.audio.player.FilePlayer.<init>(FilePlayer.java:34) at com.CreepersHelp.jda.AudioExample.onGuildMessageReceived(AudioExample.java:101) at net.dv8tion.jda.hooks.ListenerAdapter.onEvent(ListenerAdapter.java:140) at net.dv8tion.jda.hooks.InterfacedEventManager.handle(InterfacedEventManager.java:54) at net.dv8tion.jda.handle.MessageReceivedHandler.handle(MessageReceivedHandler.java:45) at net.dv8tion.jda.requests.WebSocketClient.onTextMessage(WebSocketClient.java:141) 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)
Currently it skips the name.equals check if url is null for both games, thus return true regardless.
Problem is in Line 59-65 in GameImpl.java
I got sending audio working, but what I need is to receive audio.
I understand that I need to create an AudioReceiveHandler
and play sound from the AudioPacket
provided in the handleReceivedAudio
function.
The problem is how do I play the audio from the byte array?
Hope someone can help me
I was taking a look at your source for Permission
as I was having a weird issue with the position of permissions in my library and it seems that you are missing the Use External Emojis
bit which is at position 18.
Cannot get my simple ping bot to work~
getting the following errors
[21:55:03] [Fatal] [JDA]: One of the EventListeners had an uncaught exception [21:55:03] [Fatal] [JDA]: Encountered an exception: java.lang.NullPointerException at Commands.PingCommand.action(PingCommand.java:19) at Bot1.handleCommand(Bot1.java:41) at BotListener.onMessageReceived(BotListener.java:13) at net.dv8tion.jda.hooks.ListenerAdapter.onEvent(ListenerAdapter.java:176) at net.dv8tion.jda.hooks.InterfacedEventManager.handle(InterfacedEventManager.java:57) at net.dv8tion.jda.handle.MessageReceivedHandler.handleInternally(MessageReceivedHandler.java:65) 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)
In the latest version maven is unable to resolve jflac and tritonus-dsp.
<repositories>
<repository>
<id>letece</id>
<url>http://lutece.paris.fr/nexus/content/repositories/lutece_third_party</url>
</repository>
<repository>
<id>DV8FromTheWorld</id>
<url>https://github.com/DV8FromTheWorld/Maven-Repository/raw/master/repo</url>
</repository>
</repositories>
Manually adding the repositories seems to fix it. As far as I know this isn't an issue on my side.
The main websocket uses a 2^n backoff when trying to reestablish connection to Discord. Each failed attempt increments n up to a max value of 900 or 15 minutes. When a JDA successfully reconnects to Discord it resets the backoff time back to 2 after all re-initialization has completed. This is the problem. If JDA loses connection again during a reconnect, the backoff value hasn't been reset yet, so it starts already significantly backoff'd.
To fix: Make the backoff time be reset immediately after reconnect. Don't wait for reconnect to finish.
After a few hours of operation, my bot will disconnect from Discord randomly.
Upon reconnect, JDA will setup everything as usual and will change it's status as it should. Once it's ready, it should set it to "CONNECTED" but it doesn't. It'll sometimes find it's self stuck on "LOADING_SUBSYSTEMS" but JDA will be operational. Responding to commands, processing data.
I'm not exactly sure what this could be but I'm guessing upon reconnect it's failing to set it's status. Everything else seems fine.
Running 5 shards with around 900 guilds per shard if that helps anything. Could be a sharding issue, not sure.
I've come across some weird issue. Basically this is what I want to accomplish:
The code works perfectly fine when I want to remove a single role from a user/the user only has a single role. But when there are multiple roles, it has issues.
What ends up happening/my issue:
The user has these 2 roles by default: Red and Regular. I want to remove those 2, and give them the role of Member.
I made a class called ChatHelper. It has methods that simplify my code. The methods are self explanatory and don't interfere with the problem.
This is the code
User user = CHATHELPER.getUserByUsername("testbot_wckp");
ArrayList<Role> usersRoles = new ArrayList<Role>();
// Store current roles in an array
for (Role role : CHATHELPER.getGuild().getRolesForUser(user)) {
usersRoles.add(role);
System.out.println("Added " + role.getName() + " to the array");
}
// Remove those roles from the user
for (Role role : usersRoles) {
CHATHELPER.getGuild().getManager().removeRoleFromUser(user, role).update();
}
CHATHELPER.getGuild().getManager().addRoleToUser(user, CHATHELPER.getRoleByName("Member")).update();
Console output:
Added Regular to the array
Added Red to the array
Here is the output log from my server listener:
The ending result is the user ending up with 2 roles: Member and Red, or Member and Regular.
Hello! How would I go about sending messages to a user?
The JDA emote map and the emote guild list are updated but the Guild's emote map is never updated.
This only being a reminder for me to fix it because I was the one who forgot about it >.>
I have been testing out the sending audio part of the api.
It works great aside from for some files where it is horribly distorted.
For example :
https://hydra-media.cursecdn.com/dota2.gamepedia.com/4/42/Bane_spawn_01.mp3
(I downloaded it and used the FilePlayer not URLPlayer)
was massively distorted for me
If it helps, I checked the bitrate on that file, 64kbps. The files it worked well on were around 200kbps
Another file which was very distorted was a .wav file with 700+ kbps bitrate
We are developing a discord bot and we open the an audio connection and use an AudioReceiveHandler to record audio from the channel. Then when writing it to the wav or before we get this error with the JDA Library.
[17:32:54] [Fatal] [JDAAudioConn]: Encountered an exception:
java.lang.NegativeArraySizeException
at net.dv8tion.jda.audio.Decoder.decodeFromOpus(Decoder.java:79)
at net.dv8tion.jda.audio.AudioConnection$3.run(AudioConnection.java:366)
When reading certain mp3 files i get the following:
java.io.IOException: Resetting to invalid mark at java.io.BufferedInputStream.reset(BufferedInputStream.java:448) at org.tritonus.share.sampled.file.TAudioFileReader.getAudioInputStream(TAudioFileReader.java:339) at javazoom.spi.mpeg.sampled.file.MpegAudioFileReader.getAudioInputStream(MpegAudioFileReader.java:583) at javazoom.spi.mpeg.sampled.file.MpegAudioFileReader.getAudioInputStream(MpegAudioFileReader.java:493) at javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:1181) at com.ddoggy99.discordbot.handlers.MusicHandler.playMusic(MusicHandler.java:108) at com.ddoggy99.discordbot.handlers.CommandHandler.onCommandPlay(CommandHandler.java:37) at com.ddoggy99.discordbot.handlers.CommandHandler.processCommand(CommandHandler.java:87) at com.ddoggy99.discordbot.handlers.CommandHandler.onMessageReceived(CommandHandler.java:75) at net.dv8tion.jda.hooks.ListenerAdapter.onEvent(ListenerAdapter.java:178) at net.dv8tion.jda.hooks.InterfacedEventManager.handle(InterfacedEventManager.java:64) at net.dv8tion.jda.handle.MessageReceivedHandler.handleInternally(MessageReceivedHandler.java:79) at net.dv8tion.jda.handle.SocketHandler.handle(SocketHandler.java:38) at net.dv8tion.jda.requests.WebSocketClient.handleEvent(WebSocketClient.java:571) at net.dv8tion.jda.requests.WebSocketClient.onTextMessage(WebSocketClient.java:310) 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) Caused by: java.io.IOException: Resetting to invalid mark at java.io.BufferedInputStream.reset(BufferedInputStream.java:448) at org.tritonus.share.sampled.file.TAudioFileReader.getAudioInputStream(TAudioFileReader.java:390) at org.tritonus.share.sampled.file.TAudioFileReader.getAudioInputStream(TAudioFileReader.java:329) ... 20 more
Some do work normally using mp3 and using Intellij's IDEA Debugging I can set the mark to 0 and it will then load the file fine and play it.
I am using the latest dev build 2.0.0_283 and have tried with the recommended 2.0.0_243
In JDA 3.x, we now specify all Discord Routes. These are the routes left to be added.
Class can be seen here: link
Thanks to @MinnDevelopment for writing up this list.
Base: https://discordapp.com/api/
Global Endpoints
Bot Only
Client Only
When I try to load an audio file (MP3 or WAV) 90% of the time it plays extremely distorted... (Bit crushing, pitch way too high etc.) And it does this on virtually any file. I've tested it on multiple machines. What could be causing this?
I am working on co-developing a Discord bot which needs to be able to play audio to a voice channel.
We are working on updating to JDA 3.0, but we have found that AudioManager has been removed, so we don't know how to play audio. Is there any other way which we could do this?
Thank you for your time,
MeowingTwurtle
I am trying to fix a weird issue that is causing me to not be able to stay connected and/or start a connection to the Discord API.
Is there a method to set the timeout of the bot when it is first connecting?
I have the jar implemented in my project... But why would it say this? java.lang.NoClassDefFoundError: net/dv8tion/jda/JDABuilder
When I retrieve an history with a Webhook Message inside it, JDA throws a JSONException because the object "url" is not found.
org.json.JSONException: JSONObject["url"] not found.
at org.json.JSONObject.get(JSONObject.java:477)
at org.json.JSONObject.getString(JSONObject.java:723)
at net.dv8tion.jda.handle.EntityBuilder.createMessageEmbed(EntityBuilder.java:591)
at net.dv8tion.jda.handle.EntityBuilder.createMessage(EntityBuilder.java:508)
at net.dv8tion.jda.MessageHistory.retrieve(MessageHistory.java:113)
at net.dv8tion.jda.MessageHistory.retrieve(MessageHistory.java:80)```
I've tried with JDA 2.2.1_353 and JDA 2.3.0_379, the error occurs on both.
Hey guys,
I have a pine64 which has an arm64 processor.
Whenever I want to use the audiomanager, it crashes since the natives for aarch64-linux-gnu aren't there.
This is easily fixed by recompiling JDA from the source and adding the libopus.so (I could provide that, if necessary) into main/resources/natives/linux-aarch64
While using 2.2.0_334, I updated the bot's icon, and found this in console. It doesn't seem major, but it does say to report it!
[22:21:40] [Warning] [JDASocket]: Got an unexpected Json-parse error. Please redirect following message to the devs:
JSONObject["verified"] not found.
USER_UPDATE -> {"bot":true,"id":"[REDACTED]","avatar":"[REDACTED]","username":"[REDACTED]","discriminator":"6748"}
Note, I've removed the bot's id, avatar, and username because I don't know how dangerous each code is.
With my own Discord app, when i launch a private call, it says error :
Got an unexpected Json-parse error. Please redirect following message to the devs:
JSONObject["guild_id"] not found.
VOICE_STATE_UPDATE -> {"self_deaf":false,"user_id":"189701620606673921","deaf":false,"session_id":"122732r4a68blq253159b477c1p61b1","mute":false,"suppress":false,"self_mute":false,"channel_id":null}
Got an unexpected Json-parse error. Please redirect following message to the devs:
JSONObject["embeds"] not found.
MESSAGE_UPDATE -> {"call":{"ended_timestamp":"2016-11-09T20:20:25.371089+00:00","participants":["189701620606673921"]},"id":"341012509319336417","channel_id":"17369222125631656"}
Thank you ! (It's using JDAClient but the bug is in a JDA class)
PS : i modified the ids.
Roles can be created, but they cannot be edited. Nothing happens when attempting to do so.
Happens right when I start my bot, maybe it happens when it receives a message. I have one message listener. Full source of my bot is on https://github.com/xXAndrew28Xx/SMORE-BOT
[18:06:38] [Fatal] [JDASocket]: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
at net.dv8tion.jda.handle.EntityBuilder.createGuildFirstPass(EntityBuilder.java:144)
at net.dv8tion.jda.handle.GuildJoinHandler.handleInternally(GuildJoinHandler.java:38)
at net.dv8tion.jda.handle.SocketHandler.handle(SocketHandler.java:38)
at net.dv8tion.jda.requests.WebSocketClient.handleEvent(WebSocketClient.java:629)
at net.dv8tion.jda.requests.WebSocketClient.onTextMessage(WebSocketClient.java:324)
at net.dv8tion.jda.requests.WebSocketClient.onBinaryMessage(WebSocketClient.java:705)
at com.neovisionaries.ws.client.ListenerManager.callOnBinaryMessage(ListenerManager.java:368)
at com.neovisionaries.ws.client.ReadingThread.callOnBinaryMessage(ReadingThread.java:243)
at com.neovisionaries.ws.client.ReadingThread.handleBinaryFrame(ReadingThread.java:937)
at com.neovisionaries.ws.client.ReadingThread.handleFrame(ReadingThread.java:696)
at com.neovisionaries.ws.client.ReadingThread.main(ReadingThread.java:102)
at com.neovisionaries.ws.client.ReadingThread.run(ReadingThread.java:61)
If I play a short mp3, that seems to be if it's less than 30 seconds, it turns out VERY distorted and sounds awful. I read in another issue that it might be if the audio was mono, so I converted all audio to stereo, but that's not it. I have verified that the mp3 sounds normal if played outside the bot.
Here's the code that pertains to playing:
event.getTextChannel().sendMessage("Playing " + video.title + " ID is " + video.id);
File audioFile = null;
try {
System.out.println("playing!");
audioFile = new File(video.id+".mp3");
System.out.println(audioFile.getName());
player = new FilePlayer(audioFile);
TimerTask playerStop = new PlayerStop(player);
event.getGuild().getAudioManager().setSendingHandler(player);
player.play();
t.schedule(playerStop, (long) video.duration*1000);
System.out.println("Scheduled player to stop in " + (long) video.duration + " seconds!");
} catch (IOException | UnsupportedAudioFileException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
If needed I'll give a comparison of the mp3 being played and the audio that actually is played.
I'm using 2.0.0_245 and my game/status gets reset to null after the bot auto-reconnects.
No errors are shown in the console, apart from the disconnection message.
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)
The second example does not work - the getName() call in event.getChannel().getName() does not work.
I think this is potentially related to the fact that although the Channel interface has a getName(), the MessageChannel interface, which getChannel() returns, does not.
event.getTextChannel().getName() works, but I don't think it would work in a private chat, as that's a separate interface.
Minor issue, but I felt that I should mention it, since it's on the front page of the API, essentially.
I haven't had time to test this on another Linux device yet, but I know my code works fine on Windows.
When my bot tries to connect to voice, although actually connecting to the channel succeeds, opening the audio connection fails.
The following error occurs:
java.lang.NullPointerException
at net.dv8tion.jda.audio.AudioWebSocket.send(AudioWebSocket.java:110)
at net.dv8tion.jda.audio.AudioWebSocket.onConnected(AudioWebSocket.java:124)
at com.neovisionaries.ws.client.ListenerManager.callOnConnected(ListenerManager.java:189)
at com.neovisionaries.ws.client.WebSocket.callOnConnectedIfNotYet(WebSocket.java:3207)
at com.neovisionaries.ws.client.WebSocket.onReadingThreadStarted(WebSocket.java:3152)
at com.neovisionaries.ws.client.ReadingThread.main(ReadingThread.java:80)
at com.neovisionaries.ws.client.ReadingThread.run(ReadingThread.java:61)
Exception in thread "Thread-5" Exception in thread "Thread-6" java.lang.NullPointerException
at net.dv8tion.jda.audio.AudioConnection$3.run(AudioConnection.java:224)
java.lang.NullPointerException
at net.dv8tion.jda.audio.AudioConnection$2.run(AudioConnection.java:151)
Other than that, I'd like to say that this API is brilliant and really easy to use, so thanks for all the hard work.
After reviewing reports of my bot, ErisBot disappearing from a set amount of guilds, I've found that JDA will sometimes struggle to detect the socket being closed.
I'm assuming this only affects a timeout since it doesn't always happen but have not tested.
After around 10-20 minutes after the connection has died, it finally realizes and closes, thus attempting a reconnect.
I've reported it in the Discord and @Almighty-Alpaca found that there is no timeout set on the websocket. I got asked to open a Github issue to help track this so hello!
Hello. I am using JDA2 with my Discord bot and I am encountering the following issue while leaving my bot running and it being already connected with an audio connection to a voice channel. If disconnected from the WebSocket:
[06:55:02] [Warning] [JDASocket]: Got disconnected from WebSocket (Internet?!)... Attempting to reconnect in 2s
I will eventually run into an IllegalStateException:
java.lang.IllegalStateException: Cannot have more than 1 audio connection at a time. Please close existing connection before attempting to open a new connection.
at net.dv8tion.jda.managers.impl.AudioManagerImpl.openAudioConnection(AudioManagerImpl.java:66)
at net.dv8tion.jda.requests.WebSocketClient.reconnectAudioConnections(WebSocketClient.java:483)
at net.dv8tion.jda.requests.WebSocketClient.ready(WebSocketClient.java:117)
at net.dv8tion.jda.requests.WebSocketClient.handleEvent(WebSocketClient.java:533)
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)
Any idea how I should resolve this? What essentially happens is the bot leaves the voice channel and is no longer able to rejoin it or any other channel in that particular guild.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.