Skip to content

Commit 9401ad9

Browse files
committed
fix duplicate StateListener
1 parent 19865d5 commit 9401ad9

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/main/java/net/javadiscord/javabot/Bot.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import net.dv8tion.jda.api.hooks.ListenerAdapter;
3232
import net.dv8tion.jda.api.utils.messages.MessageRequest;
3333
import net.javadiscord.javabot.data.config.BotConfig;
34+
import net.javadiscord.javabot.listener.StateListener;
3435
import net.javadiscord.javabot.systems.AutoDetectableComponentHandler;
3536
import net.javadiscord.javabot.tasks.PresenceUpdater;
3637
import net.javadiscord.javabot.util.ExceptionLogger;
@@ -41,7 +42,7 @@
4142
@SpringBootApplication
4243
@ComponentScan(
4344
includeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = { SlashCommand.class, ContextCommand.class, ListenerAdapter.class, Subcommand.class }),
44-
excludeFilters = @ComponentScan.Filter(type=FilterType.ASSIGNABLE_TYPE, classes = PresenceUpdater.class)
45+
excludeFilters = @ComponentScan.Filter(type=FilterType.ASSIGNABLE_TYPE, classes = {PresenceUpdater.class, StateListener.class})
4546
)
4647
@EnableScheduling
4748
@RequiredArgsConstructor

src/main/java/net/javadiscord/javabot/SpringConfig.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,19 @@ public SystemsConfig systemsConfig(BotConfig botConfig) {
6565
* Initializes the {@link JDA} instances.
6666
* @param botConfig the main configuration of the bot
6767
* @param stateListener The {@link StateListener} which is listening for JDA lifecycle events and needs to be added before JDA is fully initialized
68+
* @param presenceUpdater A {@link ListenerAdapter} responsible for updating the status/(rich) presence of the bot
6869
* @return the initialized {@link JDA} object
6970
* @throws LoginException if the token is invalid
7071
*/
7172
@Bean
72-
public JDA jda(BotConfig botConfig, StateListener stateListener) throws LoginException {
73+
public JDA jda(BotConfig botConfig, StateListener stateListener, PresenceUpdater presenceUpdater) throws LoginException {
7374
return JDABuilder.createDefault(botConfig.getSystems().getJdaBotToken())
7475
.setStatus(OnlineStatus.DO_NOT_DISTURB)
7576
.setChunkingFilter(ChunkingFilter.ALL)
7677
.setMemberCachePolicy(MemberCachePolicy.ALL)
7778
.enableCache(CacheFlag.ACTIVITY)
7879
.enableIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_PRESENCES, GatewayIntent.MESSAGE_CONTENT)
79-
.addEventListeners(stateListener)
80+
.addEventListeners(stateListener, presenceUpdater)
8081
.build();
8182
}
8283

0 commit comments

Comments
 (0)