本文整理汇总了Java中net.dv8tion.jda.core.JDA类的典型用法代码示例。如果您正苦于以下问题:Java JDA类的具体用法?Java JDA怎么用?Java JDA使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JDA类属于net.dv8tion.jda.core包,在下文中一共展示了JDA类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Command
import net.dv8tion.jda.core.JDA; //导入依赖的package包/类
/**
* The command
*
* @param jda The current JDA instance
* @param exHandler The handler that will catch the sub commands call exceptions
*
* @param parent The command parent (if it is a sub command)
* @param label The command label (By exemple in !command <arg> the label is '!command')
* @param description The description of the command
* @param arguments The arguments that the command can receive
* @param middlewares The middlewares of the command
* @param handler The handler of the command call
*/
public Command(JDA jda, ExceptionHandler exHandler, Command parent, String label, String description, CommandArgument[] arguments, Middleware[] middlewares, CommandHandler handler)
{
this.jda = jda;
this.exHandler = exHandler;
this.parent = parent;
this.label = label;
this.description = description;
this.arguments = arguments;
this.middlewares = middlewares;
this.handler = handler;
this.subs = new ArrayList<>();
BotRequires botRequires = handler.getClass().getAnnotation(BotRequires.class);
UserRequires userRequires = handler.getClass().getAnnotation(UserRequires.class);
this.botPermissions = botRequires != null ? botRequires.value() : new Permission[0];
this.callerPermissions = userRequires != null ? userRequires.value() : new Permission[0];
}
示例2: inspect
import net.dv8tion.jda.core.JDA; //导入依赖的package包/类
private void inspect() throws InterruptedException {
List<FredBoat> shards = FredBoat.getShards();
for(FredBoat shard : shards) {
ShardWatchdogListener listener = shard.getShardWatchdogListener();
long diff = System.currentTimeMillis() - listener.getLastEventTime();
if(diff > ACCEPTABLE_SILENCE) {
if (shard.getJda().getStatus() == JDA.Status.SHUTDOWN) {
log.warn("Did not revive shard " + shard.getShardInfo() + " because it was shut down!");
} else if(listener.getEventCount() < 100) {
log.warn("Did not revive shard " + shard.getShardInfo() + " because it did not receive enough events since construction!");
} else {
log.warn("Reviving shard " + shard.getShardInfo() + " after " + (diff / 1000) +
" seconds of no events. Last event received was " + listener.getLastEvent());
shard.revive();
sleep(5000);
}
}
}
}
示例3: onCommand
import net.dv8tion.jda.core.JDA; //导入依赖的package包/类
/**
* The method to handle the command.
*
* @param jda The JDA instance.
* @param message The message sent.
*/
@RegisterCommand(aliases = "rewards",
usage = "{prefix}rewards",
description = "Displays the possible rewards from levelling up.")
public void onCommand(JDA jda, Message message) {
EmbedBuilder embed = new EmbedBuilder();
embed.setAuthor("Rewards", null, jda.getSelfUser().getEffectiveAvatarUrl());
embed.setColor(Color.decode(Config.EMBED_COLOUR));
for (int level : AutoRole.roles.keySet()) {
String role = AutoRole.roles.get(level).get("name").toString();
embed.addField(role, "Rewarded at level " + level + ".", true);
}
message.getChannel().sendMessage(embed.build()).complete();
}
示例4: getUsersThatDonated
import net.dv8tion.jda.core.JDA; //导入依赖的package包/类
public List<User> getUsersThatDonated(JDA jda)
{
try
{
Statement statement = connection.createStatement();
statement.closeOnCompletion();
List<User> users;
try(ResultSet results = statement.executeQuery("SELECT user_id, donated_amount FROM PROFILES"))
{
users = new LinkedList<>();
while(results.next())
{
User u = jda.retrieveUserById(results.getLong("user_id")).complete();
if(hasDonated(u))
users.add(u);
}
}
return users;
}
catch(SQLException e)
{
LOG.warn(e.toString());
return null;
}
}
示例5: getDtoForView
import net.dv8tion.jda.core.JDA; //导入依赖的package包/类
public WebHookDto getDtoForView(long guildId, WebHook webHook) {
WebHookDto hookDto = mapper.getWebHookDto(webHook);
if (discordService.isConnected()) {
JDA jda = discordService.getJda();
Guild guild = jda.getGuildById(guildId);
if (guild != null && guild.getSelfMember().hasPermission(Permission.MANAGE_WEBHOOKS)) {
hookDto.setAvailable(true);
Webhook webhook = webHookService.getWebHook(guild, webHook);
if (webhook != null) {
hookDto.setChannelId(webhook.getChannel().getIdLong());
} else {
hookDto.setEnabled(false);
}
}
}
return hookDto;
}
示例6: buildAsync
import net.dv8tion.jda.core.JDA; //导入依赖的package包/类
@Override
public JDA buildAsync() throws LoginException, IllegalArgumentException, RateLimitedException {
OkHttpClient.Builder httpClientBuilder = this.httpClientBuilder == null ? new OkHttpClient.Builder() : this.httpClientBuilder;
WebSocketFactory wsFactory = this.wsFactory == null ? new WebSocketFactory() : this.wsFactory;
ClientJDA jda = new ClientJDA(accountType, httpClientBuilder, wsFactory, shardRateLimiter,
autoReconnect, enableVoice, enableShutdownHook, enableBulkDeleteSplitting,
requestTimeoutRetry, corePoolSize, maxReconnectDelay, gatewayClient);
if(eventManager != null)
jda.setEventManager(eventManager);
if(audioSendFactory != null)
jda.setAudioSendFactory(audioSendFactory);
listeners.forEach(jda::addEventListener);
jda.setStatus(JDA.Status.INITIALIZED); //This is already set by JDA internally, but this is to make sure the listeners catch it.
// Set the presence information before connecting to have the correct information ready when sending IDENTIFY
((PresenceImpl) jda.getPresence())
.setCacheGame(game)
.setCacheIdle(idle)
.setCacheStatus(status);
jda.login(token, shardInfo, reconnectQueue);
return jda;
}
示例7: buildAsync
import net.dv8tion.jda.core.JDA; //导入依赖的package包/类
@Override
public JDA buildAsync() throws LoginException, IllegalArgumentException, RateLimitedException {
OkHttpClient.Builder httpClientBuilder = this.httpClientBuilder == null ? new OkHttpClient.Builder() : this.httpClientBuilder;
WebSocketFactory wsFactory = this.wsFactory == null ? new WebSocketFactory() : this.wsFactory;
ServerJDA jda = new ServerJDA(accountType, httpClientBuilder, wsFactory, shardRateLimiter,
autoReconnect, enableVoice, enableShutdownHook, enableBulkDeleteSplitting,
requestTimeoutRetry, corePoolSize, maxReconnectDelay, gatewayServer);
if(eventManager != null)
jda.setEventManager(eventManager);
if(audioSendFactory != null)
jda.setAudioSendFactory(audioSendFactory);
listeners.forEach(jda::addEventListener);
jda.setStatus(JDA.Status.INITIALIZED); //This is already set by JDA internally, but this is to make sure the listeners catch it.
// Set the presence information before connecting to have the correct information ready when sending IDENTIFY
((PresenceImpl) jda.getPresence())
.setCacheGame(game)
.setCacheIdle(idle)
.setCacheStatus(status);
jda.login(token, shardInfo, reconnectQueue);
return jda;
}
示例8: onGuildLeave
import net.dv8tion.jda.core.JDA; //导入依赖的package包/类
@Override
public void onGuildLeave( GuildLeaveEvent event )
{
/* Disabled reactive database pruning as the Discord API seems to like to send GuildLeave notifications
during discord outages
// purge the leaving guild's entry list
Main.getDBDriver().getEventCollection().deleteMany(eq("guildId", event.getGuild().getId()));
// remove the guild's schedules
Main.getDBDriver().getScheduleCollection().deleteMany(eq("guildId", event.getGuild().getId()));
// remove the guild's settings
Main.getDBDriver().getGuildCollection().deleteOne(eq("_id", event.getGuild().getId()));
*/
JDA.ShardInfo info = event.getJDA().getShardInfo();
HttpUtilities.updateStats(info==null ? null : info.getShardId());
}
示例9: run
import net.dv8tion.jda.core.JDA; //导入依赖的package包/类
@Override
public boolean run(DiscordBot bot, GuildMessageReceivedEvent event, String args) {
Message message = event.getMessage();
TextChannel channel = event.getChannel();
JDA shard = event.getJDA();
if (!embedHasAvatarURL) {
embedBuilder.setAuthor("Safety Jim", null, shard.getSelfUser().getAvatarUrl());
embed = embedBuilder.build();
embedHasAvatarURL = true;
}
DiscordUtils.successReact(bot, message);
DiscordUtils.sendMessage(channel, embed);
return false;
}
示例10: verifyAnnouncementAdd
import net.dv8tion.jda.core.JDA; //导入依赖的package包/类
/**
* Returns error message (or empty string) for announcement add keyword verification
*/
public static String verifyAnnouncementAdd(String[] args, int index, String head, MessageReceivedEvent event)
{
if (args.length - index < 3)
{
return "That's not the right number of arguments for **" + args[index - 2] +" "+ args[index - 1] + "**!\n" +
"Use ``" + head + " " + args[0] + " " + args[index - 2] + " " + args[index - 1] + " [#target] [time] [message]``";
}
JDA jda = Main.getShardManager().getJDA(event.getGuild().getId());
String channelId = args[index].replaceAll("[^\\d]", "");
if (!channelId.matches("\\d+") || jda.getTextChannelById(channelId)==null)
{
return "**" + args[index] + "** is not a channel on your server!";
}
if(!VerifyUtilities.verifyTimeString(args[index+1]))
{
return "**" + args[index+1] + "** is not a properly formed announcement time!\n" +
"Times use the format \"TYPE+/-OFFSET\". Ex: ``START+10m``, ``END-1h``";
}
return "";
}
示例11: addRSVPReaction
import net.dv8tion.jda.core.JDA; //导入依赖的package包/类
/**
* helper to addRSVPReactions(..)
* @param emoji string emoticon, or emote ID
* @param message message object to react to
*/
private static void addRSVPReaction(String emoji, Message message)
{
if(EmojiManager.isEmoji(emoji))
{
message.addReaction(emoji).queue();
}
else
{
Emote emote;
for(JDA shard : Main.getShardManager().getShards())
{
emote = shard.getEmoteById(emoji);
if(emote != null)
{
message.addReaction(emote).queue();
break;
}
}
}
}
示例12: onMessageReceived
import net.dv8tion.jda.core.JDA; //导入依赖的package包/类
@Override
public void onMessageReceived(MessageReceivedEvent event) {
JDA jda = event.getJDA();
long responseNumber = event.getResponseNumber();
User author = event.getAuthor(); //The user that sent the message
Message message = event.getMessage(); //The message that was received
MessageChannel channel = event.getChannel(); //The channel the message was sent in
TransparentDiscord.receiveMessage(message, channel);
}
示例13: getHelpMessage
import net.dv8tion.jda.core.JDA; //导入依赖的package包/类
public static String getHelpMessage(JDA jda) {
String out = "```md\n" +
"< Music Commands >\n" +
",,join\n" +
"#Joins your voice chat and begin playing.\n" +
",,leave\n" +
"#Leaves the voice chat, stopping the music\n" +
",,np\n" +
"#Shows the song currently playing in a nice embed\n" +
",,stats\n" +
"#Displays stats about this bot\n" +
",,help\n" +
"#Displays this help message\n" +
"\n\n" +
"Invite this bot: https://discordapp.com/oauth2/authorize?&client_id=" + jda.getSelfUser().getId() + "&scope=bot\n" +
"Source code: https://github.com/Frederikam/GensokyoBot\n\n{0}" +
"```";
out = out.replaceAll(",,", Config.CONFIG.getPrefix());
if(Config.CONFIG.getStreamUrl().equals(Config.GENSOKYO_RADIO_STREAM_URL)) {
out = out.replaceFirst("\\{0}", "Content provided by gensokyoradio.net.\nThe GR logo is a trademark of Gensokyo Radio.\nGensokyo Radio is © LunarSpotlight.\n");
} else {
out = out.replaceFirst("\\{0}", "");
}
return out;
}
示例14: getGuilds
import net.dv8tion.jda.core.JDA; //导入依赖的package包/类
public static List<Guild> getGuilds() {
Set<Guild> guilds = new LinkedHashSet<Guild>();
for (JDA jda : Bot.shards) {
guilds.addAll(jda.getGuilds());
}
return new ArrayList<Guild>(guilds);
}
示例15: onMessageReceived
import net.dv8tion.jda.core.JDA; //导入依赖的package包/类
/**
* NOTE THE @Override!
* This method is actually overriding a method in the ListenerAdapter class! We place an @Override annotation
* right before any method that is overriding another to guarantee to ourselves that it is actually overriding
* a method from a super class properly. You should do this every time you override a method!
* <p>
* As stated above, this method is overriding a hook method in the
* {@link net.dv8tion.jda.core.hooks.ListenerAdapter ListenerAdapter} class. It has convience methods for all JDA events!
* Consider looking through the events it offers if you plan to use the ListenerAdapter.
* <p>
* In this example, when a message is received it is printed to the console.
*
* @param event An event containing information about a {@link net.dv8tion.jda.core.entities.Message Message} that was
* sent in a channel.
*/
//All Messages recieved, from Private channels (DM), Public Channels(server/guild), Groups (Client only, we're using bot account so we can't do groups)
@Override
public void onMessageReceived(MessageReceivedEvent event) {
//These are provided with every event in JDA
JDA jda = event.getJDA(); //JDA, the core of the api.
//long responseNumber = event.getResponseNumber();//The amount of discord events that JDA has received since the last reconnect.
//Event specific information
User author = event.getAuthor(); //The user that sent the message
Message message = event.getMessage(); //The message that was received.
String msg = message.getContentDisplay(); //This returns a human readable version of the Message. Similar to
// what you would see in the client.
boolean isBotAdminOwner = isBotAdminOwner(author);
if (message.isFromType(ChannelType.TEXT)) {
if (message.isMentioned(jda.getSelfUser())) {
if (msg.contains("shutdown")) {
//Make sure we have permission
if (isBotAdminOwner) {
closeMeDown(author);
}
}
}
} else if (message.isFromType(ChannelType.PRIVATE)) {
if (msg.contains("shutdown")) {
//Make sure we have permission
if (isBotAdminOwner) {
closeMeDown(author);
}
}
}
}