net.dv8tion.jda.api.JDABuilder Java Examples

The following examples show how to use net.dv8tion.jda.api.JDABuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LavalinkTest.java    From Lavalink-Client with MIT License 6 votes vote down vote up
@BeforeAll
static void setUp() throws Exception {
    JDABuilder jdaBuilder = new JDABuilder(AccountType.BOT)
            .setToken(getSystemProperty(PROPERTY_TOKEN));

    JDA selfId = jdaBuilder.build();
    lavalink = new JdaLavalink(selfId.retrieveApplicationInfo().submit().get(30, TimeUnit.SECONDS).getId(), 1, integer -> jda);
    selfId.shutdown();

    lavalink.addNode(new URI("ws://localhost:5555"), "youshallnotpass");

    jda = jdaBuilder
            .addEventListeners(lavalink)
            .build();

    Thread.sleep(2000);

    assertTrue(lavalink.getNodes().get(0).isAvailable(), "Could not connect to lavalink server");
}
 
Example #2
Source File: DiscordBotServer.java    From MtgDesktopCompanion with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void start() throws IOException {
	try {
		initListener();
		
		
		
		jda = JDABuilder.createDefault(getString(TOKEN))
						.addEventListeners(listener)
						.build();
	
	} catch (LoginException e) {
		throw new IOException(e);
	}
	logger.info("Server " + getName() +" started");

}
 
Example #3
Source File: AudioEchoExample.java    From JDA with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws LoginException
{
    if (args.length == 0)
    {
        System.err.println("Unable to start without token!");
        System.exit(1);
    }
    String token = args[0];

    // We only need 2 gateway intents enabled for this example:
    EnumSet<GatewayIntent> intents = EnumSet.of(
        // We need messages in guilds to accept commands from users
        GatewayIntent.GUILD_MESSAGES,
        // We need voice states to connect to the voice channel
        GatewayIntent.GUILD_VOICE_STATES
    );

    // Start the JDA session with light mode (minimal cache)
    JDABuilder.createLight(token, intents)           // Use provided token from command line arguments
         .addEventListeners(new AudioEchoExample())  // Start listening with this listener
         .setActivity(Activity.listening("to jams")) // Inform users that we are jammin' it out
         .setStatus(OnlineStatus.DO_NOT_DISTURB)     // Please don't disturb us while we're jammin'
         .enableCache(CacheFlag.VOICE_STATE)         // Enable the VOICE_STATE cache to find a user's connected voice channel
         .build();                                   // Login with these options
}
 
Example #4
Source File: DiscordService.java    From Game with GNU General Public License v3.0 5 votes vote down vote up
private void startPlayerBot(final String token) {
	this.builder = new JDABuilder(AccountType.BOT);
	this.builder.setEventManager(new AnnotatedEventManager());
	this.builder.addEventListeners(this);
	this.builder.setToken(token);
	try {
		this.jda = this.builder.build();
	} catch (final LoginException a) {
		a.printStackTrace();
	}
}
 
Example #5
Source File: Bootstrap.java    From lavaplayer with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
  new JDABuilder()
      .setToken(System.getProperty("botToken"))
      .addEventListeners(new BotApplicationManager())
      .build();
}
 
Example #6
Source File: Main.java    From lavaplayer with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
  new JDABuilder(AccountType.BOT)
      .setToken(System.getProperty("botToken"))
      .addEventListeners(new Main())
      .build();
}
 
Example #7
Source File: DefaultShardManagerBuilder.java    From JDA with Apache License 2.0 3 votes vote down vote up
/**
 * Enable typing and presence update events.
 * <br>These events cover the majority of traffic happening on the gateway and thus cause a lot
 * of bandwidth usage. Disabling these events means the cache for users might become outdated since
 * user properties are only updated by presence updates.
 * <br>Default: true
 *
 * <h2>Notice</h2>
 * This disables the majority of member cache and related events. If anything in your project
 * relies on member state you should keep this enabled.
 *
 * @param  enabled
 *         True, if guild subscriptions should be enabled
 *
 * @return The DefaultShardManagerBuilder instance. Useful for chaining.
 *
 * @since  4.1.0
 *
 * @deprecated This is now superceded by {@link #setDisabledIntents(Collection)} and {@link #setMemberCachePolicy(MemberCachePolicy)}.
 *             To get identical behavior you can do {@code setMemberCachePolicy(VOICE).setDisabledIntents(GatewayIntent.GUILD_PRESENCES, GatewayIntent.GUILD_MESSAGE_TYPING, GatewayIntent.GUILD_MEMBERS)}
 */
@Nonnull
@Deprecated
@ReplaceWith("setDisabledIntents(...).setMemberCachePolicy(...)")
@DeprecatedSince("4.2.0")
public DefaultShardManagerBuilder setGuildSubscriptionsEnabled(boolean enabled)
{
    if (!enabled)
    {
        setMemberCachePolicy(MemberCachePolicy.VOICE);
        intents &= ~JDABuilder.GUILD_SUBSCRIPTIONS;
    }
    return this;
}