Jda: EventListener and ListenerAdapter at the same time

Created on 26 Jul 2016  路  1Comment  路  Source: DV8FromTheWorld/JDA

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!");
    }
}

Most helpful comment

It has nothing to do with not being able to use EventListener and ListenerAdapter at the same time. ListenerAdapter literally implements EventListener itself. You are re-implementing that method again.

Furthermore, the re-implementation isn't the problem. You're overriding the onEvent method from the ListenerAdapter and providing your own code. Of course the onEvent method in ListenerAdapter which serves all of those custom methods isn't going to fire correctly.

This is normal java stuff, not a fault of JDA. If you want to do stuff to ALL events before ListenerAdapter filters for you, then do

@Override
public void onEvent(Event event)
{
    System.out.println("Event!");
    super.onEvent(event);
}

Additionally, remove the unneeded implements EventListener from your DiscordBot class. ListenerAdapter implements it already.

Check the source of ListenerAdapter for more information.

>All comments

It has nothing to do with not being able to use EventListener and ListenerAdapter at the same time. ListenerAdapter literally implements EventListener itself. You are re-implementing that method again.

Furthermore, the re-implementation isn't the problem. You're overriding the onEvent method from the ListenerAdapter and providing your own code. Of course the onEvent method in ListenerAdapter which serves all of those custom methods isn't going to fire correctly.

This is normal java stuff, not a fault of JDA. If you want to do stuff to ALL events before ListenerAdapter filters for you, then do

@Override
public void onEvent(Event event)
{
    System.out.println("Event!");
    super.onEvent(event);
}

Additionally, remove the unneeded implements EventListener from your DiscordBot class. ListenerAdapter implements it already.

Check the source of ListenerAdapter for more information.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MinnDevelopment picture MinnDevelopment  路  5Comments

xeu100 picture xeu100  路  5Comments

AutismSpeaks picture AutismSpeaks  路  4Comments

Frederikam picture Frederikam  路  3Comments

stefaandevylder picture stefaandevylder  路  5Comments