A simple way of adding global ban functinality to any JDA bot!
- Create a BanListener object:
import net.benjaminurquhart.ksoftbans4jda.*;
...
BanListener banListener = new BanListener("KSoft Token", true);
- Register the listener:
jda.addEventListener(banListener);
That's it!
Global Ban Hander can be used to detect when the ban listener has banned a member. You can create one by implementing the GlobalBanHandler interface.
public BanHandler implements GlobalBanHandler{
@Override
public void onGlobalBanEvent(GlobalBanEvent event){
System.out.println("User " + event.getBanInfo().getEffectiveName() + " was banned in " + event.getGuild().getName());
}
@Override
public void onBannedUserJoin(BannedUserJoinEvent event){
System.out.println("Globally banned user " + event.getBanInfo() + " joined the guild " + event.getGuild().getName());
}
}
Next, register this listener:
banListener.addHandler(new BanHandler());
Both GlobalBanEvent
and BannedUserJoinEvent
have accessors for the JDA GuildMemberJoinEvent
fields