fix: create separate LavalinkManager for radio bot with its own token
Radio bot is a separate Discord bot account but shared the main bot's LavalinkManager (created with main bot's user ID). When the radio bot connected to voice, Lavalink received voice server updates mismatched with the expected user ID, causing voice connection timeout. Now the radio bot creates its own LavalinkManager with its own token, matching the pattern already used by the music bot.
This commit is contained in:
parent
7055fcb00d
commit
cfe05144f9
1 changed files with 13 additions and 7 deletions
|
|
@ -72,10 +72,15 @@ public class BotInitializer {
|
||||||
healthHttpServer.start();
|
healthHttpServer.start();
|
||||||
|
|
||||||
JDA musicJda = createMusicJDA();
|
JDA musicJda = createMusicJDA();
|
||||||
JDA radioJda = createRadioJDA();
|
JDA radioJda = null;
|
||||||
if (radioJda != null) {
|
if (config.getRadioToken() != null && !config.getRadioToken().isBlank()) {
|
||||||
radioManager.setRadioJda(radioJda);
|
LavalinkManager radioLavalink =
|
||||||
radioManager.setLavalinkManager(lavalinkManager);
|
new LavalinkManager(config, queueRepository, config.getRadioToken());
|
||||||
|
radioJda = createRadioJDA(radioLavalink);
|
||||||
|
if (radioJda != null) {
|
||||||
|
radioManager.setRadioJda(radioJda);
|
||||||
|
radioManager.setLavalinkManager(radioLavalink);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
BotCluster cluster = new BotCluster(mainJda, musicJda, radioJda);
|
BotCluster cluster = new BotCluster(mainJda, musicJda, radioJda);
|
||||||
Runtime.getRuntime()
|
Runtime.getRuntime()
|
||||||
|
|
@ -119,7 +124,7 @@ public class BotInitializer {
|
||||||
return awaitJda(builder.build());
|
return awaitJda(builder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
private JDA createRadioJDA() {
|
private JDA createRadioJDA(LavalinkManager radioLavalink) {
|
||||||
if (config.getRadioToken() == null || config.getRadioToken().isBlank()) return null;
|
if (config.getRadioToken() == null || config.getRadioToken().isBlank()) return null;
|
||||||
LoggerDecorator.startup(logger, "Инициализация radio бота...");
|
LoggerDecorator.startup(logger, "Инициализация radio бота...");
|
||||||
var builder =
|
var builder =
|
||||||
|
|
@ -129,8 +134,9 @@ public class BotInitializer {
|
||||||
GatewayIntent.GUILD_MESSAGES,
|
GatewayIntent.GUILD_MESSAGES,
|
||||||
GatewayIntent.MESSAGE_CONTENT,
|
GatewayIntent.MESSAGE_CONTENT,
|
||||||
GatewayIntent.GUILD_VOICE_STATES);
|
GatewayIntent.GUILD_VOICE_STATES);
|
||||||
if (lavalinkManager.getClient() != null) {
|
if (radioLavalink.getClient() != null) {
|
||||||
builder.setVoiceDispatchInterceptor(new JDAVoiceUpdateListener(lavalinkManager.getClient()));
|
builder.setVoiceDispatchInterceptor(
|
||||||
|
new JDAVoiceUpdateListener(radioLavalink.getClient()));
|
||||||
}
|
}
|
||||||
builder.addEventListeners(new RadioBotListener(radioManager));
|
builder.addEventListeners(new RadioBotListener(radioManager));
|
||||||
return awaitJda(builder.build());
|
return awaitJda(builder.build());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue