/** * Adds all provided listeners to the event-listeners that will be used to handle events. * * <p>Note: when using the {@link net.dv8tion.jda.core.hooks.InterfacedEventManager InterfacedEventListener} (default), * given listener <b>must</b> be instance of {@link net.dv8tion.jda.core.hooks.EventListener EventListener}! * * @param listeners * The listener(s) which will react to events. * * @throws java.lang.IllegalArgumentException * If either listeners or one of it's objects is {@code null}. */ default void addEventListener(final Object... listeners) { Checks.noneNull(listeners, "listeners"); this.getShardCache().forEach(jda -> jda.addEventListener(listeners)); }
/** * Adds listeners provided by the listener provider to each shard to the event-listeners that will be used to handle events. * The listener provider gets a shard id applied and is expected to return a listener. * * <p>Note: when using the {@link net.dv8tion.jda.core.hooks.InterfacedEventManager InterfacedEventListener} (default), * given listener <b>must</b> be instance of {@link net.dv8tion.jda.core.hooks.EventListener EventListener}! * * @param eventListenerProvider * The provider of listener(s) which will react to events. * * @throws java.lang.IllegalArgumentException * If the provided listener provider or any of the listeners or provides are {@code null}. */ default void addEventListeners(final IntFunction<Object> eventListenerProvider) { Checks.notNull(eventListenerProvider, "event listener provider"); this.getShardCache().forEach(jda -> { Object listener = eventListenerProvider.apply(jda.getShardInfo().getShardId()); if (listener != null) jda.addEventListener(listener); }); }
/** * Creates a new instance of this class. * * @param jda A JDA instance. */ public JDA3Handler(JDA jda) { jda.addEventListener(new ListenerAdapter() { @Override public void onMessageReceived(MessageReceivedEvent event) { handleMessageCreate(event); } }); }
private boolean initJDA() { try { jda = new JDABuilder(AccountType.BOT).setToken(Config.CORE.BOT_TOKEN).build().awaitReady(); jda.addEventListener(new MessageListener()); } catch (LoginException e) { logger.error("ERROR STARTING THE PLUGIN:"); logger.error("THE TOKEN IN THE CONFIG IS INVALID!"); logger.error("You probably didn't set the token yet, edit your config!"); return false; } catch (Exception e) { logger.error("Error connecting to discord. This is NOT a plugin error"); e.printStackTrace(); return false; } return true; }
public static void main(String[] args) throws Exception { JDA jda = new JDABuilder(AccountType.BOT) .setToken(System.getProperty("botToken")) .buildBlocking(); jda.addEventListener(new Main()); }
public void restartJDA() throws LoginException, InterruptedException, RateLimitedException { JDABuilder builder = new JDABuilder(AccountType.BOT).setToken(BotConfig.BOT_TOKEN); if (totShards > 1) { builder.useSharding(shardId, totShards); } builder.setBulkDeleteSplittingEnabled(false); builder.setEnableShutdownHook(false); builder.setEventManager(new JDAEventManager(this)); System.out.println("STARTING SHARD " + shardId); jda.set(builder.buildBlocking()); jda.get().addEventListener(new JDAEvents(this)); System.out.println("SHARD " + shardId + " IS READY "); // }
jda.addEventListener(new JDAListener(this)); this.defaultConfig = options.defaultConfig == null ? new JDACommandConfig() : options.defaultConfig; this.configProvider = options.configProvider;