本文整理汇总了Java中net.dv8tion.jda.JDABuilder类的典型用法代码示例。如果您正苦于以下问题:Java JDABuilder类的具体用法?Java JDABuilder怎么用?Java JDABuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JDABuilder类属于net.dv8tion.jda包,在下文中一共展示了JDABuilder类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: GnarBot
import net.dv8tion.jda.JDABuilder; //导入依赖的package包/类
private GnarBot(String token)
{
try
{
final JDA jda = new JDABuilder().setBotToken(token).buildBlocking();
jda.getAccountManager().setUsername("GNAR");
jda.getAccountManager().setGame("_help | _invite");
jda.getAccountManager().update();
jda.setAutoReconnect(true);
DiscordBotsInfo.updateServerCount(jda);
serverManager = new ServerManager(jda);
}
catch (LoginException | InterruptedException e)
{
e.printStackTrace();
}
}
示例2: main
import net.dv8tion.jda.JDABuilder; //导入依赖的package包/类
public static void main(final String[] args) throws Exception {
try {
SimpleLog.addFileLogs(null,new File("err" + System.currentTimeMillis() + ".txt"));
} catch (IOException e) {
Logger.writeToErr(e, "");
}
Dao dao = new Dao();
List<Platform> platforms;
String token = PropertiesReader.getInstance().getProp().getProperty("bot.token");
DiscordController discordController = new DiscordController(dao);
JDA jda = new JDABuilder()
.setBotToken(token)
.addListener(discordController)
.buildBlocking();
discordController.setJda(jda);
Thread messageConsumer = new MessageConsumer(MessageHandler.getQueue(), jda, dao);
messageConsumer.start();
Thread messageFinder = new MessageFinder(MessageHandler.getDeleteQueue(), jda);
messageFinder.start();
platforms = setPlatforms(dao, jda);
WebController webController = new WebController(jda, dao);
webController.serve();
platforms.forEach(Platform::checkStillOnline);
int ticks = 0;
while(true){
if(!((JDAImpl)jda).getClient().isConnected()){
while (!((JDAImpl)jda).getClient().isConnected()){
Thread.sleep(1000);
}
discordController.setJda(jda);
platforms = setPlatforms(dao, jda);
//webController.setJda(jda);
continue;
}
if(!messageConsumer.isAlive()){
messageConsumer = new MessageConsumer(MessageHandler.getQueue(), jda, dao);
messageConsumer.start();
}
if(!messageFinder.isAlive()){
messageFinder = new MessageFinder(MessageHandler.getDeleteQueue(), jda);
messageFinder.start();
}
if(ticks < 10){
Session session = HibernateUtil.getSession();
List<Long> guildIDs = session.createCriteria(GuildEntity.class)
.setProjection(Projections.property("id")).list();
List<Guild> connectedGuilds = jda.getGuilds();
for(Guild connectedGuild : connectedGuilds){
Long connectedGuildID = Long.parseLong(connectedGuild.getId());
if(guildIDs.contains(connectedGuildID)){
for(Platform platform : platforms){
platform.checkStreams(connectedGuildID);
}
}
}
ticks++;
}
else{
platforms.forEach(Platform::checkStillOnline);
ticks = 0;
}
Thread.sleep(60000);
}
}
示例3: main
import net.dv8tion.jda.JDABuilder; //导入依赖的package包/类
public static void main(String[] args) {
// Set up logging
LogManager.getLogManager().reset();
Handler handler = new ConsoleHandler();
handler.setLevel(Level.ALL);
handler.setFormatter(new LogFormatter());
Logger.getLogger("").addHandler(handler);
// Redirect default System.out to the logger (because JDA does not use java logging...)
System.setOut(new PrintStream(System.out) {
@Override
public void print(String s) {
Logger.getLogger("System.out").info(s);
}
});
LOG.info("Starting...");
// Try to find VLC
boolean found = new NativeDiscovery().discover();
if (found) LOG.info("Found VLC: " + LibVlc.INSTANCE.libvlc_get_version());
else {
LOG.severe("Could not find VLC, exiting");
System.exit(-1);
}
// AudioService
AudioService audioService = new AudioService();
try {
// Load configuration
new ConfigurationBuilder(new File("config.properties")).build();
// Start JDA
JDA jda = new JDABuilder()
.setEmail(Configuration.EMAIL)
.setPassword(Configuration.PASSWORD)
.addListener(new JoinMessageListener(audioService))
.addListener(new CommandListener(audioService))
.buildAsync();
// Log to the specified log channel
if (!Configuration.LOG_CHANNEL.isEmpty()) {
ChannelLogHandler channelLogHandler = new ChannelLogHandler(jda, new LogFormatter());
Logger.getLogger("").addHandler(channelLogHandler);
}
} catch (Exception e) {
LOG.log(Level.SEVERE, "An unexpected error occurred", e);
}
}