Search in sources :

Example 11 with IDiscordClient

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

the class EmptyBot method main.

public static void main(String[] args) {
    ((Discord4J.Discord4JLogger) Discord4J.LOGGER).setLevel(Discord4J.Discord4JLogger.Level.DEBUG);
    // Log.setLog(new Logger() {
    // @Override
    // public String getName() {
    // return "sdfsdsdfsf";
    // }
    // 
    // @Override
    // public void warn(String s, Object... objects) {
    // Discord4J.LOGGER.warn(s, objects);
    // }
    // 
    // @Override
    // public void warn(Throwable throwable) {
    // Discord4J.LOGGER.warn("", throwable);
    // }
    // 
    // @Override
    // public void warn(String s, Throwable throwable) {
    // Discord4J.LOGGER.warn(s, throwable);
    // }
    // 
    // @Override
    // public void info(String s, Object... objects) {
    // Discord4J.LOGGER.info(s, objects);
    // }
    // 
    // @Override
    // public void info(Throwable throwable) {
    // Discord4J.LOGGER.info("", throwable);
    // }
    // 
    // @Override
    // public void info(String s, Throwable throwable) {
    // Discord4J.LOGGER.info(s, throwable);
    // }
    // 
    // @Override
    // public boolean isDebugEnabled() {
    // return true;
    // }
    // 
    // @Override
    // public void setDebugEnabled(boolean b) {
    // 
    // }
    // 
    // @Override
    // public void debug(String s, Object... objects) {
    // Discord4J.LOGGER.debug(s, objects);
    // }
    // 
    // @Override
    // public void debug(String s, long l) {
    // Discord4J.LOGGER.debug(s, l);
    // }
    // 
    // @Override
    // public void debug(Throwable throwable) {
    // Discord4J.LOGGER.debug("", throwable);
    // }
    // 
    // @Override
    // public void debug(String s, Throwable throwable) {
    // Discord4J.LOGGER.debug(s, throwable);
    // }
    // 
    // @Override
    // public Logger getLogger(String s) {
    // return this;
    // }
    // 
    // @Override
    // public void ignore(Throwable throwable) {
    // 
    // }
    // });
    IDiscordClient client = new ClientBuilder().withToken(args[0]).registerListener(new IListener<ReadyEvent>() {

        @Override
        public void handle(ReadyEvent event) {
            System.out.println("Ohai");
        }
    }).login();
}
Also used : ReadyEvent(sx.blah.discord.handle.impl.events.ReadyEvent) IListener(sx.blah.discord.api.events.IListener) IDiscordClient(sx.blah.discord.api.IDiscordClient) ClientBuilder(sx.blah.discord.api.ClientBuilder)

Example 12 with IDiscordClient

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

the class Discord4J method main.

/**
 * Runs Discord4J using modules only.
 *
 * @param args The args should only include the bot token.
 */
public static void main(String[] args) {
    // This functionality is dependent on these options being true
    if (!Configuration.AUTOMATICALLY_ENABLE_MODULES || !Configuration.LOAD_EXTERNAL_MODULES)
        throw new RuntimeException("Invalid configuration! Must have auto-enabling of modules + loading of external modules enabled.");
    if (args.length == 0)
        throw new RuntimeException("Invalid configuration! No arguments passed in.");
    try {
        ClientBuilder builder = new ClientBuilder();
        IDiscordClient client = builder.withToken(args[0]).login();
        client.getDispatcher().registerListener((IListener<ReadyEvent>) (ReadyEvent e) -> {
            LOGGER.info(LogMarkers.MAIN, "Logged in as {}", e.getClient().getOurUser().getName());
        });
    // The modules should handle the rest
    } catch (DiscordException e) {
        LOGGER.error(LogMarkers.MAIN, "There was an error initializing the client", e);
    }
}
Also used : ReadyEvent(sx.blah.discord.handle.impl.events.ReadyEvent) DiscordException(sx.blah.discord.util.DiscordException) IDiscordClient(sx.blah.discord.api.IDiscordClient) ClientBuilder(sx.blah.discord.api.ClientBuilder)

Aggregations

IDiscordClient (sx.blah.discord.api.IDiscordClient)12 ClientBuilder (sx.blah.discord.api.ClientBuilder)8 ReadyEvent (sx.blah.discord.handle.impl.events.ReadyEvent)6 DiscordException (sx.blah.discord.util.DiscordException)5 IListener (sx.blah.discord.api.events.IListener)4 File (java.io.File)2 SQLException (java.sql.SQLException)2 IUser (sx.blah.discord.handle.obj.IUser)2 CommandManager (com.discordbolt.api.command.CommandManager)1 DiceModule (com.discordbolt.boltbot.modules.dice.DiceModule)1 DisconnectModule (com.discordbolt.boltbot.modules.disconnect.DisconnectModule)1 CuntModule (com.discordbolt.boltbot.modules.misc.CuntModule)1 TableFixerModule (com.discordbolt.boltbot.modules.misc.TableFixerModule)1 MusicModule (com.discordbolt.boltbot.modules.music.MusicModule)1 RedditModule (com.discordbolt.boltbot.modules.reddit.RedditModule)1 SeenModule (com.discordbolt.boltbot.modules.seen.SeenModule)1 TagModule (com.discordbolt.boltbot.modules.tags.TagModule)1 TwitchModule (com.discordbolt.boltbot.modules.twitch.TwitchModule)1 MySQL (com.discordbolt.boltbot.system.mysql.MySQL)1 DataSync (com.discordbolt.boltbot.system.mysql.data.DataSync)1