Search in sources :

Example 6 with ClientBuilder

use of sx.blah.discord.api.ClientBuilder in project DiscordSailv2 by Vaerys-Dawn.

the class Client method main.

public static void main(String[] args) {
    IDiscordClient client = new ClientBuilder().withToken(args[0]).build();
    client.getDispatcher().registerListener((IListener<ReadyEvent>) readyEvent -> System.out.println("login successful"));
    client.login();
}
Also used : RequestHandler(com.github.vaerys.handlers.RequestHandler) Campaign(com.patreon.resources.Campaign) ZonedDateTime(java.time.ZonedDateTime) LoggerFactory(org.slf4j.LoggerFactory) TimedEvent(com.github.vaerys.objects.TimedEvent) Pledge(com.patreon.resources.Pledge) HttpStatusException(org.jsoup.HttpStatusException) ReadyEvent(sx.blah.discord.handle.impl.events.ReadyEvent) ArrayList(java.util.ArrayList) PasteBin(com.github.kennedyoliveira.pastebin4j.PasteBin) ZoneOffset(java.time.ZoneOffset) Logger(org.slf4j.Logger) IEmoji(sx.blah.discord.handle.obj.IEmoji) PatreonOAuth(com.patreon.PatreonOAuth) EventAvatar(com.github.vaerys.objects.EventAvatar) IOException(java.io.IOException) FileHandler(com.github.vaerys.handlers.FileHandler) AccountCredentials(com.github.kennedyoliveira.pastebin4j.AccountCredentials) File(java.io.File) IDiscordClient(sx.blah.discord.api.IDiscordClient) Image(sx.blah.discord.util.Image) List(java.util.List) StringHandler(com.github.vaerys.handlers.StringHandler) IListener(sx.blah.discord.api.events.IListener) DiscordException(sx.blah.discord.util.DiscordException) PatreonAPI(com.github.vaerys.objects.PatreonAPI) FilenameUtils(org.apache.commons.io.FilenameUtils) ClientBuilder(sx.blah.discord.api.ClientBuilder) ReadyEvent(sx.blah.discord.handle.impl.events.ReadyEvent) IDiscordClient(sx.blah.discord.api.IDiscordClient) ClientBuilder(sx.blah.discord.api.ClientBuilder)

Example 7 with ClientBuilder

use of sx.blah.discord.api.ClientBuilder in project de-DiscordBot by DACH-Discord.

the class Authorization method createClient.

public static IDiscordClient createClient(final String token, final boolean login) {
    // Creates the ClientBuilder instance
    ClientBuilder clientBuilder = new ClientBuilder();
    // Adds the login info to the builder
    clientBuilder.withToken(token);
    try {
        if (login) {
            // Creates the client instance and logs the client in
            return clientBuilder.login();
        } else {
            // Creates the client instance but it doesn't log the client in yet, you would have to call client.login() yourself
            return clientBuilder.build();
        }
    } catch (DiscordException e) {
        // This is thrown if there was a problem building the client
        Util.error(e);
        return null;
    }
}
Also used : DiscordException(sx.blah.discord.util.DiscordException) ClientBuilder(sx.blah.discord.api.ClientBuilder)

Example 8 with ClientBuilder

use of sx.blah.discord.api.ClientBuilder in project solinia3-core by mixxit.

the class Solinia3CorePlugin method createClient.

public static IDiscordClient createClient(String token, boolean login) {
    ClientBuilder clientBuilder = new ClientBuilder();
    clientBuilder.withToken(token);
    try {
        if (login) {
            return clientBuilder.login();
        } else {
            return clientBuilder.build();
        }
    } catch (DiscordException e) {
        e.printStackTrace();
        return null;
    }
}
Also used : DiscordException(sx.blah.discord.util.DiscordException) ClientBuilder(sx.blah.discord.api.ClientBuilder)

Example 9 with ClientBuilder

use of sx.blah.discord.api.ClientBuilder in project DisCal-Discord-Bot by NovaFox161.

the class Main method createClient.

/**
 * Creates the DisCal bot client.
 *
 * @param token The Bot Token.
 * @return The client if successful, otherwise <code>null</code>.
 */
private static IDiscordClient createClient(String token) {
    // Creates the ClientBuilder instance
    ClientBuilder clientBuilder = new ClientBuilder();
    // Adds the login info to the builder
    clientBuilder.withToken(token).withRecommendedShardCount();
    try {
        return clientBuilder.login();
    } catch (DiscordException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : DiscordException(sx.blah.discord.util.DiscordException) ClientBuilder(sx.blah.discord.api.ClientBuilder)

Example 10 with ClientBuilder

use of sx.blah.discord.api.ClientBuilder in project Discord4J by Discord4J.

the class BaseBot method login.

/**
 * A custom login() method to handle all of the possible exceptions and set the bot instance.
 */
public static BaseBot login(String token) {
    // Initializing the bot variable
    BaseBot bot = null;
    // Creates a new client builder instance
    ClientBuilder builder = new ClientBuilder();
    // Sets the bot token for the client
    builder.withToken(token);
    try {
        // Builds the IDiscordClient instance and logs it in
        IDiscordClient client = builder.login();
        // Creating the bot instance
        bot = new BaseBot(client);
    } catch (DiscordException e) {
        // Error occurred logging in
        System.err.println("Error occurred while logging in!");
        e.printStackTrace();
    }
    return bot;
}
Also used : DiscordException(sx.blah.discord.util.DiscordException) IDiscordClient(sx.blah.discord.api.IDiscordClient) ClientBuilder(sx.blah.discord.api.ClientBuilder)

Aggregations

ClientBuilder (sx.blah.discord.api.ClientBuilder)14 DiscordException (sx.blah.discord.util.DiscordException)8 IDiscordClient (sx.blah.discord.api.IDiscordClient)7 ReadyEvent (sx.blah.discord.handle.impl.events.ReadyEvent)5 IListener (sx.blah.discord.api.events.IListener)3 File (java.io.File)2 AccountCredentials (com.github.kennedyoliveira.pastebin4j.AccountCredentials)1 PasteBin (com.github.kennedyoliveira.pastebin4j.PasteBin)1 FileHandler (com.github.vaerys.handlers.FileHandler)1 RequestHandler (com.github.vaerys.handlers.RequestHandler)1 StringHandler (com.github.vaerys.handlers.StringHandler)1 EventAvatar (com.github.vaerys.objects.EventAvatar)1 PatreonAPI (com.github.vaerys.objects.PatreonAPI)1 TimedEvent (com.github.vaerys.objects.TimedEvent)1 PatreonOAuth (com.patreon.PatreonOAuth)1 Campaign (com.patreon.resources.Campaign)1 Pledge (com.patreon.resources.Pledge)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 ZoneOffset (java.time.ZoneOffset)1