本文整理汇总了Java中net.dv8tion.jda.core.JDABuilder类的典型用法代码示例。如果您正苦于以下问题:Java JDABuilder类的具体用法?Java JDABuilder怎么用?Java JDABuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JDABuilder类属于net.dv8tion.jda.core包,在下文中一共展示了JDABuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import net.dv8tion.jda.core.JDABuilder; //导入依赖的package包/类
public static void main(String[] args) {
try{
new Database();
OkHttpClient.Builder httpBuilder = new OkHttpClient.Builder().readTimeout(60, TimeUnit.SECONDS).connectTimeout(60, TimeUnit.SECONDS).writeTimeout(60, TimeUnit.SECONDS);
JDA jda = new JDABuilder(AccountType.BOT).setToken(Tokens.TOKEN).setHttpClientBuilder(httpBuilder).buildBlocking();
jda.setAutoReconnect(true);
jda.addEventListener(new EventHandler(jda));
}catch(Exception ex){
ex.printStackTrace();
}
}
示例2: main
import net.dv8tion.jda.core.JDABuilder; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
//Code by ZekroTJA(github.com/ZekroTJA)
StartArgumentHandler.args = args;
//MY CODE
builder = new JDABuilder(AccountType.BOT)
.setToken(SECRETS.TOKEN)
.setAudioEnabled(true)
.setAutoReconnect(true)
.setStatus(STATICS.STATUS)
.setGame(Game.of(STATICS.CUSTOM_MESSAGE + " | _help | coded by Lee", "http://twitch.tv/lordleeyt"))
;
initializeListeners();
initializeCommands();
SQL.connect();
LVL.connect();
try {
builder.buildBlocking();
} catch (InterruptedException | RateLimitedException | LoginException e) {
e.printStackTrace();
}
}
示例3: start
import net.dv8tion.jda.core.JDABuilder; //导入依赖的package包/类
public void start() throws RateLimitedException, InterruptedException, LoginException {
this.discordAPI = new JDABuilder(AccountType.BOT)
.setToken(settings.getToken())
.setGame(new GameImpl(settings.getGame(), settings.getGameUrl(), settings.isTwitch() ? Game.GameType.TWITCH : Game.GameType.DEFAULT))
.addListener(new EventCaller(this))
.setAutoReconnect(true)
.setAudioEnabled(true)
.setBulkDeleteSplittingEnabled(false)
.buildBlocking();
if (settings.getRedis().isEnabled()) {
redisConnection.start();
keepDataThread.start();
}
initCommands();
initListeners();
}
示例4: initDiscord
import net.dv8tion.jda.core.JDABuilder; //导入依赖的package包/类
private static void initDiscord() {
JDABuilder builder = new JDABuilder(AccountType.BOT);
try {
builder.setToken(BotConfig.DISCORD_TOKEN);
builder.setAutoReconnect(true);
builder.setStatus(OnlineStatus.ONLINE);
builder.addEventListener(new ReadyListener());
builder.addEventListener(new MessageListener());
builder.buildBlocking();
} catch (Throwable e) {
e.printStackTrace();
} finally {
builder.setStatus(OnlineStatus.OFFLINE);
}
}
示例5: setup
import net.dv8tion.jda.core.JDABuilder; //导入依赖的package包/类
/**
* Setup this bot.
*/
private void setup() {
if (Configs.getMainConfig().getDiscordToken() == null) {
Core.warn("Discord Token is not set, discord integrations will not function.");
return;
}
try {
bot = new JDABuilder(AccountType.BOT).setToken(Configs.getMainConfig().getDiscordToken())
.addEventListener(this).setAutoReconnect(true).setGame(Game.of("Kineticraft"))
.setStatus(OnlineStatus.ONLINE).buildAsync(); // Setup listener and connect to discord.
active = true;
} catch (Exception e) {
e.printStackTrace();
Core.warn("Failed to setup discord bot.");
}
}
示例6: start
import net.dv8tion.jda.core.JDABuilder; //导入依赖的package包/类
public void start() throws LoginException, InterruptedException, RateLimitedException {
running = true;
// init logger
AnsiConsole.systemInstall();
log = Logger.getLogger("Kyoko");
log.setUseParentHandlers(false);
ColoredFormatter formatter = new ColoredFormatter();
ConsoleHandler handler = new ConsoleHandler();
handler.setFormatter(formatter);
log.addHandler(handler);
log.info("Kyoko v" + Constants.VERSION + " is starting...");
i18n.loadMessages();
JDABuilder builder = new JDABuilder(AccountType.BOT);
if (settings.getToken() != null) {
if (settings.getToken().equalsIgnoreCase("Change me")) {
System.out.println("No token specified, please set it in config.json");
System.exit(1);
}
builder.setToken(settings.getToken());
}
boolean gameEnabled = false;
if (settings.getGame() != null && !settings.getGame().isEmpty()) {
gameEnabled = true;
builder.setGame(Game.of("booting..."));
}
builder.setAutoReconnect(true);
builder.setBulkDeleteSplittingEnabled(false);
builder.addEventListener(eventHandler);
builder.setAudioEnabled(true);
builder.setStatus(OnlineStatus.IDLE);
jda = builder.buildBlocking();
log.info("Invite link: " + "https://discordapp.com/oauth2/authorize?&client_id=" + jda.getSelfUser().getId() + "&scope=bot&permissions=" + Constants.PERMISSIONS);
if (gameEnabled) {
Thread t = new Thread(new Kyoko.BlinkThread());
t.start();
}
registerCommands();
}
示例7: loadDiscord
import net.dv8tion.jda.core.JDABuilder; //导入依赖的package包/类
public void loadDiscord() {
try {
jda = new JDABuilder(AccountType.BOT)
.setToken(DiscordBot.getInstance().getConfig().getToken())
.addEventListener(new DiscordListener())
.setAudioEnabled(true)
.setBulkDeleteSplittingEnabled(false)
.buildAsync();
AudioSourceManagers.registerRemoteSources(getAudioPlayerManager());
audioPlayer = getAudioPlayerManager().createPlayer();
getAudioPlayer().setVolume(DiscordBot.getInstance().getConfig().getDefaultVolume());
getAudioPlayer().addListener(new AudioListener());
getDiscordThread().start();
getCommand().registerCommands();
LogHelper.info("Successfully loaded Discord.");
} catch (LoginException | RateLimitedException | RuntimeException ex) {
LogHelper.error("Exception loading Discord!");
ex.printStackTrace();
}
}
示例8: postInit
import net.dv8tion.jda.core.JDABuilder; //导入依赖的package包/类
public void postInit() {
String token = getConfiguration().getToken();
JDABuilder jdaBuilder = null;
if (token != null && !token.equals("") && !token.equals("null")) {
jdaBuilder = new JDABuilder(AccountType.BOT).setToken(token);
}
token = null;
if (jdaBuilder == null) {
getLogger().severe("Cannot start DiscordBot, No Token / Email and Password provided!");
return;
}
try {
jda = jdaBuilder
.addEventListener(new BotListener())
.setAudioEnabled(false)
.setBulkDeleteSplittingEnabled(false)
.buildAsync();
} catch (IllegalArgumentException | LoginException | RateLimitedException ex) {
getLogger().severe("Connection Failed! Invalid BotToken");
ex.printStackTrace();
}
}
示例9: initJda
import net.dv8tion.jda.core.JDABuilder; //导入依赖的package包/类
/**
* Starts JDA.
*
* @return {@code true} if everything went well, {@code false} otherwise.
*/
private boolean initJda() {
try {
SimpleLog.Level level = JDAImpl.LOG.getLevel();
SimpleLog.Level socketLevel = WebSocketClient.LOG.getLevel();
JDAImpl.LOG.setLevel(SimpleLog.Level.OFF);
WebSocketClient.LOG.setLevel(SimpleLog.Level.OFF);
jda = new JDABuilder(AccountType.BOT).setToken(botToken).buildBlocking();
jda.getPresence().setGame(Game.of("2.0.2"));
logger.writeFrom("jda", "Successfully connected!");
logger.writeFrom("jda WebSocket", "Connected to WebSocket!");
JDAImpl.LOG.setLevel(level);
WebSocketClient.LOG.setLevel(socketLevel);
} catch (LoginException | InterruptedException | RateLimitedException e) {
logger.writeFrom("jda", "Couldn't connect!");
e.printStackTrace();
return false;
}
return true;
}
示例10: SelfBot
import net.dv8tion.jda.core.JDABuilder; //导入依赖的package包/类
public SelfBot() {
config = new LoadingProperties();
clientID = config.getClientID();
prefix = config.getPrefix();
pwd = config.getPwd();
try {
jda = new JDABuilder(AccountType.CLIENT).setToken(config.getToken()).buildBlocking();
jda.addEventListener(new CommandListener());
jda.getPresence().setGame(Game.of(config.getActivity()));
System.out.println("\nSelfbot ready !");
} catch (InterruptedException | LoginException | RateLimitedException e) {
System.out.println("No internet connection or invalid or missing token. Please edit config.blue and try again.");
}
//Commands
commands.put("lenny", new LennyCommand());
commands.put("game", new GameCommand());
commands.put("avatars", new AvatarCommand());
commands.put("ascii", new AsciiCommand());
commands.put("info", new InfoCommand());
commands.put("whois", new WhoisCommand());
commands.put("poll", new PollCommand());
commands.put("server", new ServerCommand());
commands.put("idgf", new IdgfCommand());
commands.put("binary", new BinaryCommand());
commands.put("reverse", new ReverseCommand());
}
示例11: registerEventListeners
import net.dv8tion.jda.core.JDABuilder; //导入依赖的package包/类
public void registerEventListeners(JDABuilder jda) {
if (!classLoader.getPlugin().getEventListeners().isEmpty()) {
for (ListenerAdapter adapter : classLoader.getPlugin().getEventListeners()) {
jda.addEventListener(adapter);
}
}
}
示例12: main
import net.dv8tion.jda.core.JDABuilder; //导入依赖的package包/类
public static final void main(String[] args) {
try {
Standard.setStarted(Instant.now());
System.setOut(new SystemOutputStream(System.out, false));
System.setErr(new SystemOutputStream(System.err, true));
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
//Standard.STANDARD_SETTINGS.saveSettings(); //FIXME WTF This is deleting the settings file all the time?!
Standard.saveAllGuildSettings();
}));
Standard.JDA_SUPPLIER = () -> jda;
NetworkUtil.init();
reload();
MySQL.init();
builder = new JDABuilder(AccountType.BOT);
builder.setAutoReconnect(true);
//builder.setAudioSendFactory(null);
builder.setStatus(OnlineStatus.ONLINE);
builder.setGame(game = Game.of("Supreme-Bot"));
initListeners();
initCommands();
init();
initPlugins();
loadAllGuilds();
startJDA();
} catch (Exception ex) {
System.err.println("Main Error: " + ex);
ex.printStackTrace();
}
}
示例13: restartJDA
import net.dv8tion.jda.core.JDABuilder; //导入依赖的package包/类
public void restartJDA(boolean force) throws RateLimitedException, LoginException, InterruptedException {
if (jda != null) {
log.info("Attempting to drop shard #" + shardId);
if (!force) prepareShutdown();
jda.shutdown(false);
log.info("Dropped shard #" + shardId);
}
JDABuilder jdaBuilder = new JDABuilder(AccountType.BOT)
.setToken(config().get().token)
.setEventManager(manager)
.setAutoReconnect(true)
.setCorePoolSize(15)
.setGame(Game.of("Hold on to your seatbelts!"));
if (totalShards > 1)
jdaBuilder.useSharding(shardId, totalShards);
jda = jdaBuilder.buildBlocking();
readdListeners();
}
示例14: initJDA
import net.dv8tion.jda.core.JDABuilder; //导入依赖的package包/类
/**
* Initializes the JDA instance.
*/
public static void initJDA() {
if (instance == null)
throw new NullPointerException("RubiconBot has not been initialized yet.");
JDABuilder builder = new JDABuilder(AccountType.BOT);
builder.setToken(instance.configuration.getString("token"));
builder.setGame(Game.playing("Starting...."));
// add all EventListeners
for (EventListener listener : instance.eventListeners)
builder.addEventListener(listener);
new ListenerManager(builder);
try {
instance.jda = builder.buildBlocking();
} catch (LoginException | InterruptedException e) {
Logger.error(e.getMessage());
}
CommandVote.loadPolls(instance.jda);
Info.lastRestart = new Date();
// CommandGiveaway.startGiveawayManager(instance.jda);
getJDA().getPresence().setGame(Game.playing("Started."));
GameAnimator.start();
}
示例15: ShardingManager
import net.dv8tion.jda.core.JDABuilder; //导入依赖的package包/类
public ShardingManager(int numShards, boolean supportScript) throws Exception {
Config config = Config.getInstance();
shards = new JDA[numShards];
Bot bot = null;
CommandClient client = null;
if (!supportScript) {
bot = new Bot(new EventWaiter());
CommandClientBuilder commandClientBuilder = new CommandClientBuilder();
commandClientBuilder.setPrefix("~");
commandClientBuilder.setOwnerId(config.getConfig(Config.OWNER_ID));
commandClientBuilder.addCommands(new TestCommand(),
new PlayCommand(bot),
new PauseCommand(),
new RepeatCommand(),
new StopCommand(),
new ResumeCommand(),
new ListTracksCommand());
commandClientBuilder.setEmojis("\u2714", "\u2757", "\u274c");
client = commandClientBuilder.build();
}
for (int i = 0; i < numShards; i++){
shards[i] = new JDABuilder(AccountType.BOT)
.setToken(config.getConfig(Config.DISCORD_TOKEN))
.useSharding(i, numShards)
.buildBlocking();
if (!supportScript) {
EventWaiter waiter = new EventWaiter();
shards[i].addEventListener(waiter);
shards[i].addEventListener(client);
shards[i].addEventListener(bot);
}
System.out.println("Shard " + i + " built.");
}
}