Java Code Examples for net.dv8tion.jda.api.entities.MessageEmbed#Field
The following examples show how to use
net.dv8tion.jda.api.entities.MessageEmbed#Field .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HelpEmbeds.java From SkyBot with GNU Affero General Public License v3.0 | 6 votes |
public static MessageEmbed generateCommandEmbed(String prefix, CommandCategory... categories) { final EmbedBuilder embed = defaultEmbed() .setTitle("Click here for the support server", "https://dunctebot.link/server") .setDescription("Use `" + prefix + "help [command]` to get more info about a command\n"); if (categories == null || categories.length == 0) { addAllCategoriesToEmbed(embed); } else { for (final CommandCategory category : categories) { final MessageEmbed.Field generated = getFieldForCategory(category); if (generated != null) { embed.addField(generated); } } } return embed.addField("Support", "Support server: [https://dunctebot.link/server](https://dunctebot.link/server)\n" + "Support development of this bot: [https://www.patreon.com/DuncteBot](https://www.patreon.com/DuncteBot)", false) .build(); }
Example 2
Source File: DiscordUtils.java From MantaroBot with GNU General Public License v3.0 | 6 votes |
public static List<List<MessageEmbed.Field>> divideFields(int max, List<MessageEmbed.Field> fields) { List<MessageEmbed.Field> temp = new LinkedList<>(); List<List<MessageEmbed.Field>> m = new LinkedList<>(); while (fields.size() > 0) { if (temp.size() < max) { temp.add(fields.get(0)); fields.remove(0); } else { m.add(temp); temp = new LinkedList<>(); } } if (temp.size() != 0) m.add(temp); return m; }
Example 3
Source File: HelpEmbeds.java From SkyBot with GNU Affero General Public License v3.0 | 5 votes |
private static MessageEmbed.Field getFieldForCategory(CommandCategory category) { if ("unlisted".equalsIgnoreCase(category.name())) { return null; } final Class<?> cls = HelpEmbeds.class; final String fieldName = category.name() + "_COMMANDS"; final String descFieldName = category.name() + "_COMMANDS_DESC"; try { final Field field = cls.getDeclaredField(fieldName); final Field descField = cls.getDeclaredField(descFieldName); return new MessageEmbed.Field( (String) descField.get(cls), (String) field.get(cls), INLINE ); } catch (NoSuchFieldException ignored) { return null; } catch (IllegalAccessException e) { e.printStackTrace(); } return null; }
Example 4
Source File: DiscordUtils.java From MantaroBot with GNU General Public License v3.0 | 5 votes |
private static EmbedBuilder addAllFields(EmbedBuilder builder, List<MessageEmbed.Field> fields) { builder.clearFields(); for (MessageEmbed.Field f : fields) { builder.addField(f); } return builder; }
Example 5
Source File: SteamCommand.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
private MessageEmbed.Field getReleaseDate(SteamAppReleaseDate releaseDate) { StringBuilder builder = new StringBuilder(); if (releaseDate.isComingSoon()) { builder.append(messageService.getMessage("discord.command.steam.releaseDate.comingSoon")).append(" "); } if (StringUtils.isNotEmpty(releaseDate.getDate())) { builder.append(releaseDate.getDate()); } return new MessageEmbed.Field(messageService.getMessage("discord.command.steam.releaseDate"), builder.toString(), true); }
Example 6
Source File: SteamCommand.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
private MessageEmbed.Field getPlatforms(SteamAppPlatforms platforms) { StringBuilder builder = new StringBuilder(); if (platforms.isWindows()) { builder.append("<:windows:636568315354939392> "); } if (platforms.isLinux()) { builder.append("<:steamos:636568315111800847> "); } if (platforms.isMac()) { builder.append("<:macos:636568314965131267> "); } return new MessageEmbed.Field(messageService.getMessage("discord.command.steam.platforms"), builder.toString(), true); }
Example 7
Source File: ServerInfoCommand.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
protected MessageEmbed.Field getChannelListField(Guild guild) { long total = guild.getTextChannels().size() + guild.getVoiceChannels().size(); StringBuilder memberBuilder = new StringBuilder(); if (!guild.getTextChannels().isEmpty()) { memberBuilder.append(messageService.getMessage("discord.command.server.channels.text", guild.getTextChannels().size())).append("\n"); } if (!guild.getVoiceChannels().isEmpty()) { memberBuilder.append(messageService.getMessage("discord.command.server.channels.voice", guild.getVoiceChannels().size())).append("\n"); } return new MessageEmbed.Field(messageService.getMessage("discord.command.server.channels", total), memberBuilder.toString(), true); }
Example 8
Source File: StatsCommand.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
private MessageEmbed.Field getPlatformStats(Map<String, Metric> metricMap) { String value = getGaugeValue(metricMap, "jvm.uptime", e -> { Date date = new Date(); date.setTime(date.getTime() - (long) e); return new PrettyTime(contextService.getLocale()).format(date); }); return value != null ? new MessageEmbed.Field(messageService.getMessage("discord.command.stats.platform"), value, false) : null; }
Example 9
Source File: ServerInfoCommand.java From JuniperBot with GNU General Public License v3.0 | 4 votes |
protected MessageEmbed.Field getVerificationLevel(Guild.VerificationLevel level) { return new MessageEmbed.Field(messageService.getMessage("discord.command.server.verificationLevel"), messageService.getEnumTitle(level), true); }
Example 10
Source File: ServerInfoCommand.java From JuniperBot with GNU General Public License v3.0 | 4 votes |
protected MessageEmbed.Field getOwner(Guild guild) { return new MessageEmbed.Field(messageService.getMessage("discord.command.server.owner"), DiscordUtils.formatUser(guild.getOwner().getUser()), true); }
Example 11
Source File: ServerInfoCommand.java From JuniperBot with GNU General Public License v3.0 | 4 votes |
protected MessageEmbed.Field getRegion(Guild guild) { return new MessageEmbed.Field(messageService.getMessage("discord.command.server.region"), messageService.getEnumTitle(guild.getRegion()), true); }
Example 12
Source File: ServerInfoCommand.java From JuniperBot with GNU General Public License v3.0 | 4 votes |
protected MessageEmbed.Field getShard(Guild guild) { return new MessageEmbed.Field(messageService.getMessage("discord.command.server.shard.title"), String.format("#**%s**", guild.getJDA().getShardInfo().getShardId() + 1), true); }
Example 13
Source File: ServerInfoCommand.java From JuniperBot with GNU General Public License v3.0 | 4 votes |
protected MessageEmbed.Field getMemberListField(Guild guild) { List<Member> memberList = guild.getMembers(); class Info { private long userCount = 0; private long botCount = 0; private long online = 0; private long offline = 0; private long dnd = 0; private long idle = 0; } Info memberInfo = new Info(); guild.getMembers().forEach(member -> { User user = member.getUser(); if (user.isBot()) { memberInfo.botCount++; } else { memberInfo.userCount++; } switch (member.getOnlineStatus()) { case ONLINE: memberInfo.online++; break; case OFFLINE: case INVISIBLE: memberInfo.offline++; break; case IDLE: memberInfo.idle++; break; case DO_NOT_DISTURB: memberInfo.dnd++; break; } }); StringBuilder memberBuilder = new StringBuilder(); if (memberInfo.userCount > 0) { memberBuilder.append(messageService.getMessage("discord.command.server.members.users", memberInfo.userCount)) .append("\n"); } if (memberInfo.botCount > 0) { memberBuilder.append(messageService.getMessage("discord.command.server.members.bots", memberInfo.botCount)) .append("\n"); } if (memberInfo.online > 0) { memberBuilder.append(messageService.getMessage("discord.command.server.members.status.online", memberInfo.online)) .append("\n"); } if (memberInfo.idle > 0) { memberBuilder.append(messageService.getMessage("discord.command.server.members.status.idle", memberInfo.idle)) .append("\n"); } if (memberInfo.dnd > 0) { memberBuilder.append(messageService.getMessage("discord.command.server.members.status.dnd", memberInfo.dnd)) .append("\n"); } if (memberInfo.offline > 0) { memberBuilder.append(messageService.getMessage("discord.command.server.members.status.offline", memberInfo.offline)) .append("\n"); } return new MessageEmbed.Field(messageService.getMessage("discord.command.server.members", memberList.size()), memberBuilder.toString(), true); }
Example 14
Source File: StatsCommand.java From JuniperBot with GNU General Public License v3.0 | 4 votes |
private MessageEmbed.Field getCommandStats(Map<String, Metric> metricMap) { String value = getCounterValue(metricMap, "commands.executions.persist") + "\n" + getMeterValue(metricMap, "commands.executions.rate"); return new MessageEmbed.Field(messageService.getMessage("discord.command.stats.commands"), value, true); }
Example 15
Source File: SteamCommand.java From JuniperBot with GNU General Public License v3.0 | 4 votes |
private MessageEmbed.Field getParts(List<String> parts, String messageCode) { return new MessageEmbed.Field(messageService.getMessage(messageCode), StringUtils.join(parts, "\n"), true); }
Example 16
Source File: DiscordUtils.java From MantaroBot with GNU General Public License v3.0 | 4 votes |
public static Future<Void> list(GuildMessageReceivedEvent event, int timeoutSeconds, boolean canEveryoneUse, EmbedBuilder base, List<List<MessageEmbed.Field>> parts) { if (parts.size() == 0) return null; for (MessageEmbed.Field f : parts.get(0)) { base.addField(f); } if (parts.size() == 1) { event.getChannel().sendMessage(base.build()).queue(); return null; } AtomicInteger index = new AtomicInteger(); Message m = event.getChannel().sendMessage(base.build()).complete(); return ReactionOperations.create(m, timeoutSeconds, (e) -> { if (!canEveryoneUse && e.getUser().getIdLong() != event.getAuthor().getIdLong()) return Operation.IGNORED; switch (e.getReactionEmote().getName()) { //left arrow case "\u2b05" -> { if (index.get() == 0) break; EmbedBuilder toSend = addAllFields(base, parts.get(index.decrementAndGet())); toSend.setFooter("Current page: " + (index.get() + 1), event.getAuthor().getEffectiveAvatarUrl()); m.editMessage(toSend.build()).queue(); } //right arrow case "\u27a1" -> { if (index.get() + 1 >= parts.size()) break; EmbedBuilder toSend1 = addAllFields(base, parts.get(index.incrementAndGet())); toSend1.setFooter("Current page: " + (index.get() + 1), event.getAuthor().getEffectiveAvatarUrl()); m.editMessage(toSend1.build()).queue(); } } if (event.getGuild().getSelfMember().hasPermission(e.getTextChannel(), Permission.MESSAGE_MANAGE)) { e.getReaction().removeReaction(e.getUser()).queue(); } return Operation.IGNORED; }, "\u2b05", "\u27a1"); }
Example 17
Source File: AbstractInfoCommand.java From JuniperBot with GNU General Public License v3.0 | 4 votes |
protected MessageEmbed.Field getDateField(long epochSecond, String nameKey, DateTimeFormatter formatter) { DateTime dateTime = new DateTime(epochSecond * 1000); return new MessageEmbed.Field(messageService.getMessage(nameKey), String.format("**%s**", formatter.print(dateTime)), true); }
Example 18
Source File: MafiaHelpCommand.java From JuniperBot with GNU General Public License v3.0 | 4 votes |
public MessageEmbed.Field getField(String title, String content) { return new MessageEmbed.Field(messageService.getMessage(title) + ":", messageService.getMessage(content) + "\n" + EmbedBuilder.ZERO_WIDTH_SPACE, true); }
Example 19
Source File: EmbedBuilder.java From JDA with Apache License 2.0 | 2 votes |
/** * <b>Modifiable</b> list of {@link net.dv8tion.jda.api.entities.MessageEmbed MessageEmbed} Fields that the builder will * use for {@link #build()}. * <br>You can add/remove Fields and restructure this {@link java.util.List List} and it will then be applied in the * built MessageEmbed. These fields will be available again through {@link net.dv8tion.jda.api.entities.MessageEmbed#getFields() MessageEmbed.getFields()}. * * @return Mutable List of {@link net.dv8tion.jda.api.entities.MessageEmbed.Field Fields} */ @Nonnull public List<MessageEmbed.Field> getFields() { return fields; }
Example 20
Source File: EmbedBuilder.java From JDA with Apache License 2.0 | 2 votes |
/** * Copies the provided Field into a new Field for this builder. * <br>For additional documentation, see {@link #addField(String, String, boolean)} * * @param field * the field object to add * * @return the builder after the field has been added */ @Nonnull public EmbedBuilder addField(@Nullable MessageEmbed.Field field) { return field == null ? this : addField(field.getName(), field.getValue(), field.isInline()); }