I've been programming a Discord Bot using Lavaplayer and the JDA and they work fine, but sometimes the bot is extremely laggy. When I invited other bots before, they also lagged (but often times not as hard as mine). The difference to other questions on StackOverflow concerning this topic is, that my bot is already lagging when I start it locally, which makes me think, that my code is wrong. Sometimes it works for 10 minutes and then it lags for 5 minutes, sometimes it lags for 20 minutes and then works fine for 1 minute; very inconsistent. I run my bot on a raspberry (but that's not the reason and my internet connection is also good enough); it sounds like if a cache, buffer or something is overflowing or there may be lots packets being lost and the audio is very distorted.
I uploaded the code for the bot on GitHub. (Only the "Musikroboter" class has a German name, the rest should be English)
Edit: Others also experience these lags.
The most common issues that can cause lags are:
You can use jda-nas to avoid the issue of GC pauses interrupting your playback.
The main downside of jda-nas, is that you can no longer use voice receive if you change your send-factory.
Another alternative is to use lavalink, but setting that up requires some extra effort.