Java Code Examples for net.dv8tion.jda.core.EmbedBuilder#addField()
The following examples show how to use
net.dv8tion.jda.core.EmbedBuilder#addField() .
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: HelpCommand.java From DiscordBot with Apache License 2.0 | 6 votes |
@Override public void execute(TextChannel textChannel, Member member, Message message, List<String> arguments) { EmbedBuilder embedBuilder = new EmbedBuilder(); embedBuilder.setAuthor(textChannel.getJDA().getSelfUser().getName(), null, textChannel.getJDA().getSelfUser().getEffectiveAvatarUrl()); embedBuilder.setColor(DiscordUtil.DEFAULT); embedBuilder.setTitle("Commands", null); for (Iterator<ICommand> iterator = DiscordBot.getInstance().getDiscord().getCommand().getRegisteredCommands().iterator(); iterator.hasNext();) { ICommand command = iterator.next(); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("Description - " + command.getDescription() + "\n"); stringBuilder.append("Usage - " + command.getUsage() + "\n"); if (command.getAliases() != null && !command.getAliases().isEmpty()) { stringBuilder.append("Aliases - " + String.join(", ", command.getAliases())); } embedBuilder.addField(command.getName(), stringBuilder.toString(), false); } embedBuilder.setFooter("<> = Required Argument, [] = Optional Argument", null); DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true); }
Example 2
Source File: NowPlayingCommand.java From DiscordBot with Apache License 2.0 | 6 votes |
@Override public void execute(TextChannel textChannel, Member member, Message message, List<String> arguments) { EmbedBuilder embedBuilder = new EmbedBuilder(); embedBuilder.setAuthor(textChannel.getJDA().getSelfUser().getName(), null, textChannel.getJDA().getSelfUser().getEffectiveAvatarUrl()); embedBuilder.setColor(DiscordUtil.DEFAULT); AudioTrack audioTrack = DiscordBot.getInstance().getDiscord().getAudioPlayer().getPlayingTrack(); if (audioTrack == null) { embedBuilder.setTitle("Nothing is currently playing.", null); DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true); return; } embedBuilder.addField("Now playing", audioTrack.getInfo().title, false); embedBuilder.setFooter(DiscordUtil.getTimestamp(audioTrack.getPosition()) + " / " + DiscordUtil.getTimestamp(audioTrack.getDuration()), null); DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true); }
Example 3
Source File: MessageUtils.java From FlareBot with MIT License | 6 votes |
public static void sendUsage(Command command, TextChannel channel, User user, String[] args) { String title = capitalize(command.getCommand()) + " Usage"; List<String> usages = UsageParser.matchUsage(command, args); String usage = FormatUtils.formatCommandPrefix(channel.getGuild(), usages.stream().collect(Collectors.joining("\n"))); EmbedBuilder b = getEmbed(user).setTitle(title, null).setDescription(usage).setColor(Color.pink); if (command.getExtraInfo() != null) { b.addField("Extra Info", command.getExtraInfo(), false); } if (command.getPermission() != null) { b.addField("Permission", "`" + command.getPermission() + "`\n\n" + "Default Permission: " + command.getPermission().isDefaultPerm() + "\n" + "Beta Command: " + command.isBetaTesterCommand(), false); } channel.sendMessage(b.build()).queue(); }
Example 4
Source File: PagedEmbedBuilder.java From FlareBot with MIT License | 6 votes |
/** * Gets the {@link MessageEmbed} for a specified page. * * @param page The page to get an embed. * @return the {@link MessageEmbed} page. */ public MessageEmbed getEmbed(int page) { EmbedBuilder pageEmbed = new EmbedBuilder().setColor(ColorUtils.FLAREBOT_BLUE); if (title != null) pageEmbed.setTitle(title); if(useGroups) { int start = groupsPerPage * (page); int end = Math.min(start + groupsPerPage, groupTotal); int num = start; List<PaginationList<T>.PageGroup> groups = list.getGroups().subList(start, end); for (PaginationList.PageGroup group : groups) { pageEmbed.addField(groupPrefix + num, group.getGroupAsString(), false); num++; } } else { pageEmbed.setDescription((hasCodeBlock ? "```" + codeBlock + "\n" : "") + list.getPage(page) + (hasCodeBlock ? "\n```" : "")); } if (pageCounts) { pageEmbed.addField("Page", String.valueOf(page + 1), true); pageEmbed.addField("Total Pages", String.valueOf(pageTotal), true); } pageEmbed.setColor(color); return pageEmbed.build(); }
Example 5
Source File: GeneralUtils.java From FlareBot with MIT License | 6 votes |
/** * This is to handle "multi-selection commands" for example the info and stats commands which take one or more * arguments and get select data from an enum */ public static void handleMultiSelectionCommand(User sender, TextChannel channel, String[] args, MultiSelectionContent<String, String, Boolean>[] providedContent) { String search = MessageUtils.getMessage(args); String[] fields = search.split(","); EmbedBuilder builder = MessageUtils.getEmbed(sender).setColor(Color.CYAN); boolean valid = false; for (String string : fields) { String s = string.trim(); for (MultiSelectionContent<String, String, Boolean> content : providedContent) { if (s.equalsIgnoreCase(content.getName()) || s.replaceAll("_", " ") .equalsIgnoreCase(content.getName())) { builder.addField(content.getName(), content.getReturn(), content.isAlign()); valid = true; } } } if (valid) channel.sendMessage(builder.build()).queue(); else MessageUtils.sendErrorMessage("That piece of information could not be found!", channel); }
Example 6
Source File: GeneralUtils.java From FlareBot with MIT License | 6 votes |
/** * Gets the {@link Report} embed with all of the info on the report. * * @param sender The {@link User} who requested the embed * @param report The {@link Report} to get the embed of. * @return an {@link EmbedBuilder} that contains all the report data */ public static EmbedBuilder getReportEmbed(User sender, Report report) { EmbedBuilder eb = MessageUtils.getEmbed(sender); User reporter = Getters.getUserById(report.getReporterId()); User reported = Getters.getUserById(report.getReportedId()); eb.addField("Report ID", String.valueOf(report.getId()), true); eb.addField("Reporter", reporter != null ? MessageUtils.getTag(reporter) : "Unknown", true); eb.addField("Reported", reported != null ? MessageUtils.getTag(reported) : "Unknown", true); //eb.addField("Time", report.getTime().toLocalDateTime().atOffset(ZoneOffset.UTC).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) + " GMT/BST", true); eb.setTimestamp(report.getTime().toLocalDateTime()); eb.addField("Status", report.getStatus().getMessage(), true); eb.addField("Message", "```" + report.getMessage() + "```", false); StringBuilder builder = new StringBuilder("The last 5 messages by the reported user: ```\n"); for (ReportMessage m : report.getMessages()) { builder.append("[").append(m.getTime().toLocalDateTime().format(DateTimeFormatter.ofPattern("HH:mm:ss"))).append(" GMT/BST] ") .append(FormatUtils.truncate(100, m.getMessage())) .append("\n"); } builder.append("```"); eb.addField("Messages from reported user", builder.toString(), false); return eb; }
Example 7
Source File: InfoCommand.java From DiscordBot with Apache License 2.0 | 5 votes |
@Override public void execute(TextChannel textChannel, Member member, Message message, List<String> arguments) { EmbedBuilder embedBuilder = new EmbedBuilder(); embedBuilder.setAuthor(Reference.APP_NAME + " v" + Reference.APP_VERSION, null, textChannel.getJDA().getSelfUser().getEffectiveAvatarUrl()); embedBuilder.setColor(DiscordUtil.DEFAULT); embedBuilder.addField("Author", String.join(", ", Reference.AUTHORS), false); embedBuilder.addField("Source", Reference.SOURCE, false); embedBuilder.addField("Website", Reference.WEBSITE, false); embedBuilder.addField("Dependencies", "" + "\n- " + Reference.JDA_NAME + " v" + Reference.JDA_VERSION + "\n- " + Reference.LAVA_NAME + " v" + Reference.LAVA_VERSION, false); DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true); }
Example 8
Source File: AudioQueue.java From DiscordBot with Apache License 2.0 | 5 votes |
public void playNext() { Audio audio = getNext(); if (audio == null) { DiscordBot.getInstance().getDiscord().getAudioPlayer().playTrack(null); return; } DiscordBot.getInstance().getDiscord().getAudioPlayer().playTrack(audio.getAudioTrack()); EmbedBuilder embedBuilder = new EmbedBuilder(); embedBuilder.setAuthor(audio.getTextChannel().getJDA().getSelfUser().getName(), null, audio.getTextChannel().getJDA().getSelfUser().getEffectiveAvatarUrl()); embedBuilder.setColor(DiscordUtil.DEFAULT); embedBuilder.addField("Now playing", audio.getAudioTrack().getInfo().title, false); DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(audio.getTextChannel(), embedBuilder.build(), true); }
Example 9
Source File: Constants.java From FlareBot with MIT License | 5 votes |
public static void logEG(String eg, Command command, Guild guild, User user) { EmbedBuilder builder = new EmbedBuilder().setTitle("Found `" + eg + "`") .addField("Guild", guild.getId() + " (`" + guild.getName() + "`) ", true) .addField("User", user.getAsMention() + " (`" + user.getName() + "#" + user.getDiscriminator() + "`)", true) .setTimestamp(LocalDateTime.now(Clock.systemUTC())); if (command != null) builder.addField("Command", command.getCommand(), true); Constants.getEGLogChannel().sendMessage(builder.build()).queue(); }
Example 10
Source File: ModlogEvents.java From FlareBot with MIT License | 5 votes |
private void handleChannelDelete(GuildWrapper wrapper, Channel channel) { if (wrapper == null) return; if (cannotHandle(wrapper, ModlogEvent.CHANNEL_DELETE)) return; AuditLogEntry entry = wrapper.getGuild().getAuditLogs().complete().get(0); EmbedBuilder builder = new EmbedBuilder() .addField("Type", channel.getType().name().toLowerCase(), true) .addField("Name", channel.getName(), true); if (channel.getParent() != null) { builder.addField("Category", channel.getParent().getName(), true); } ModlogHandler.getInstance().postToModlog(wrapper, ModlogEvent.CHANNEL_DELETE, entry.getUser(), builder); }
Example 11
Source File: ModlogEvents.java From FlareBot with MIT License | 5 votes |
private void handleChannelCreate(GuildWrapper wrapper, Channel channel) { if (cannotHandle(wrapper, ModlogEvent.CHANNEL_CREATE)) return; AuditLogEntry entry = wrapper.getGuild().getAuditLogs().complete().get(0); EmbedBuilder builder = new EmbedBuilder() .addField("Type", channel.getType().name().toLowerCase(), true) .addField("Name", channel.getName(), true); if (channel.getParent() != null) { builder.addField("Category", channel.getParent().getName(), true); } ModlogHandler.getInstance().postToModlog(wrapper, ModlogEvent.CHANNEL_CREATE, entry.getUser(), builder); }
Example 12
Source File: QueryCommand.java From FlareBot with MIT License | 5 votes |
@Override public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) { try { CassandraController.runUnsafeTask(conn -> { ResultSet set = conn.execute(MessageUtils.getMessage(args, 0)); List<String> header = new ArrayList<>(); List<List<String>> table = new ArrayList<>(); int columnsCount = set.getColumnDefinitions().size(); for (int i = 0; i < columnsCount; i++) { header.add(set.getColumnDefinitions().getName(i)); } for (Row setRow : set) { List<String> row = new ArrayList<>(); for (int i = 0; i < columnsCount; i++) { String value = setRow.getObject(i).toString(); row.add(value.substring(0, Math.min(30, value.length()))); } table.add(row); } String output = MessageUtils.makeAsciiTable(header, table, null); if (output.length() < 2000) { channel.sendMessage(output).queue(); } else { MessageUtils.sendErrorMessage("The query result set was very large, it has been posted to paste [here](" + MessageUtils .paste(output) + ")", channel, sender); } }); } catch (QueryExecutionException | QueryValidationException e) { EmbedBuilder eb = new EmbedBuilder(); eb.setTitle("Failed to execute query"); eb.addField("Error", "```\n" + e.getMessage() + "\n```", false); channel.sendMessage(eb.build()).queue(); } }
Example 13
Source File: AudioPlayerLoadResultHandler.java From DiscordBot with Apache License 2.0 | 5 votes |
@Override public void loadFailed(FriendlyException exception) { LogHelper.error("Failed to load - " + exception.getMessage()); exception.printStackTrace(); EmbedBuilder embedBuilder = new EmbedBuilder(); embedBuilder.setAuthor(textChannel.getJDA().getSelfUser().getName(), null, textChannel.getJDA().getSelfUser().getEffectiveAvatarUrl()); embedBuilder.setColor(DiscordUtil.ERROR); embedBuilder.addField("Failed to load", exception.getMessage(), false); DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true); }
Example 14
Source File: SourcesCommand.java From DiscordBot with Apache License 2.0 | 5 votes |
@Override public void execute(TextChannel textChannel, Member member, Message message, List<String> arguments) { EmbedBuilder embedBuilder = new EmbedBuilder(); embedBuilder.setAuthor(textChannel.getJDA().getSelfUser().getName(), null, textChannel.getJDA().getSelfUser().getEffectiveAvatarUrl()); embedBuilder.setColor(DiscordUtil.DEFAULT); embedBuilder.addField("Sources", String.join(",\n", DiscordBot.getInstance().getConfig().getAllowedSources()), false); DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true); }
Example 15
Source File: DonateCommand.java From FlareBot with MIT License | 5 votes |
@Override public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) { EmbedBuilder builder = MessageUtils.getEmbed(sender); builder.setColor(Color.CYAN); builder.setDescription("Thank for you taking the time to see how you can donate to the project! This project relies heavily upon user donations so every little helps! \uD83D\uDE0A"); builder.addField("Patreon", "The most common way to donate is through our [Patreon page](https://www.patreon.com/flarebot)! Through here you can donate the amount you want and also get rewarded for it!", false); builder.addField("PayPal", "If you cannot donate through Patreon or don't like the idea of a monthly subscription then this option is for you! Simply join our [support server](" + Constants.INVITE_URL + ") and our amazing staff will assist you in doing this!\n\nShould you want to donate anonymously or you don't want to receive a reward, you can simply send money to `[email protected]` via PayPal to donate!", false); channel.sendMessage(builder.build()).queue(); }
Example 16
Source File: InfoCommand.java From FlareBot with MIT License | 5 votes |
@Override public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) { if (args.length == 0) { EmbedBuilder bld = MessageUtils.getEmbed() .setThumbnail(MessageUtils.getAvatar(channel.getJDA().getSelfUser())) .setFooter("Made by Walshy#9060 and BinaryOverload#2382", channel.getJDA().getSelfUser().getEffectiveAvatarUrl()); bld.setDescription("FlareBot v" + FlareBot.getVersion() + " info") .setColor(Color.CYAN); for (Content content : Content.values) { bld.addField(content.getName(), content.getReturn(), content.isAlign()); } channel.sendMessage(bld.build()).queue(); } else GeneralUtils.handleMultiSelectionCommand(sender, channel, args, Content.values); }
Example 17
Source File: SongCommand.java From FlareBot with MIT License | 5 votes |
public static void updateSongMessage(User sender, Message message, TextChannel channel) { Track track = FlareBot.instance().getMusicManager().getPlayer(channel.getGuild().getId()).getPlayingTrack(); if (track == null) return; EmbedBuilder eb = MessageUtils.getEmbed(sender) .addField("Current Song", getLink(track), false) .setThumbnail("https://img.youtube.com/vi/" + track.getTrack().getIdentifier() + "/hqdefault.jpg"); if (track.getTrack().getInfo().isStream) eb.addField("Amount Played", "Issa livestream ;)", false); else eb.addField("Amount Played", GeneralUtils.getProgressBar(track), true) .addField("Time", String.format("%s / %s", FormatUtils.formatDuration(track.getTrack().getPosition()), FormatUtils.formatDuration(track.getTrack().getDuration())), false); message.editMessage(eb.build()).queue(); }
Example 18
Source File: PlayCommand.java From DiscordBot with Apache License 2.0 | 4 votes |
@Override public void execute(TextChannel textChannel, Member member, Message message, List<String> arguments) { EmbedBuilder embedBuilder = new EmbedBuilder(); embedBuilder.setAuthor(textChannel.getJDA().getSelfUser().getName(), null, textChannel.getJDA().getSelfUser().getEffectiveAvatarUrl()); embedBuilder.setColor(DiscordUtil.DEFAULT); if (member.getGuild().getAudioManager().getConnectedChannel() == null) { embedBuilder.setColor(DiscordUtil.ERROR); embedBuilder.setTitle("Not connected to voice channel!", null); DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true); return; } if (arguments == null || arguments.isEmpty()) { if (DiscordBot.getInstance().getDiscord().getAudioPlayer().isPaused()) { DiscordBot.getInstance().getDiscord().getAudioPlayer().setPaused(false); embedBuilder.setColor(DiscordUtil.SUCCESS); embedBuilder.setTitle("Playback resumed.", null); } else { DiscordBot.getInstance().getDiscord().getAudioPlayer().setPaused(true); embedBuilder.setColor(DiscordUtil.WARNING); embedBuilder.setTitle("Playback paused.", null); } DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true); return; } embedBuilder.setColor(DiscordUtil.SUCCESS); for (Iterator<String> iterator = arguments.iterator(); iterator.hasNext();) { String string = iterator.next(); URL url = DiscordUtil.encodeURL(string); if (url == null) { embedBuilder.setColor(DiscordUtil.WARNING); embedBuilder.addField("Invalid URL!", string, false); continue; } if (!DiscordBot.getInstance().getConfig().getAllowedSources().contains(url.getHost())) { embedBuilder.setColor(DiscordUtil.WARNING); embedBuilder.addField("This source is not allowed!", string, false); continue; } DiscordBot.getInstance().getDiscord().getAudioPlayerManager().loadItem(string, new AudioPlayerLoadResultHandler(textChannel, member)); embedBuilder.addField("Processing", string, false); } DiscordBot.getInstance().getDiscord().getMessageSender().sendMessage(textChannel, embedBuilder.build(), true); }
Example 19
Source File: MultiPollCommand.java From DiscordBlueBot with MIT License | 4 votes |
@Override public void action(String[] args, MessageReceivedEvent event) { String query = ""; String subject; String choicesList = ""; ArrayList<String> choices = new ArrayList<>(); Pattern subjectRegex = Pattern.compile("\\((.*?)\\)"); Pattern choiceRegex = Pattern.compile("\\[(.*?)]"); for (String arg : args) { query += arg + " "; } Matcher subjectMatcher = subjectRegex.matcher(query); Matcher choiceMatcher = choiceRegex.matcher(query); while (choiceMatcher.find()) { choices.add(choiceMatcher.group(1)); } if (subjectMatcher.find()) { subject = subjectMatcher.group(1); } else { event.getTextChannel().sendMessage("Please provide a poll question/subject.").queue(); return; } if(choices.size() < 2 || choices.size() > 10) { //At least 2 options and max 10 event.getTextChannel().sendMessage("You can only propose from 2 to 10 options.").queue(); return; } EmbedBuilder builder = new EmbedBuilder(); builder.setColor(Color.decode(MainBot.getConfig().getEmbedColor())); builder.setAuthor(event.getAuthor().getName() + "#" + event.getAuthor().getDiscriminator() + " created a poll", null, event.getAuthor().getAvatarUrl()); builder.addField("", "Question : " + "**" + subject + "**", true); for(int i = 0; i < choices.size(); ++i) { if(i == 9) { choicesList = choicesList + "\uD83D\uDD1F " + choices.get(i); //Keycap 10 case break; } choicesList = choicesList + (i+1) + "⃣ " + choices.get(i) + "\n"; //damn these emojis made me mad } builder.addField("", choicesList, false); builder.setFooter("Vote by adding a reaction below !", null); event.getMessage().delete().queue(); event.getTextChannel().sendMessage(builder.build()).queue(); //Now retrieves the last message from BlueBot to add reactions List<Message> history = event.getTextChannel().getHistory().retrievePast(10).complete(); //arbitrary ammount for (Message msg : history) { if(msg.getAuthor().getId().equals(event.getJDA().getSelfUser().getId())) { for(int i = 0; i < choices.size(); ++i) { if(i == 9) { msg.addReaction("\uD83D\uDD1F").queue(); //Keycap 10 case break; } msg.addReaction(i+1 + "⃣").queue(); //damn these emojis made me mad } break; } } }
Example 20
Source File: SongCommand.java From FlareBot with MIT License | 4 votes |
@Override public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) { PlayerManager manager = FlareBot.instance().getMusicManager(); if (manager.getPlayer(channel.getGuild().getId()).getPlayingTrack() != null) { Track track = manager.getPlayer(channel.getGuild().getId()).getPlayingTrack(); EmbedBuilder eb = MessageUtils.getEmbed(sender) .addField("Current Song", getLink(track), false) .setThumbnail("https://img.youtube.com/vi/" + track.getTrack().getIdentifier() + "/hqdefault.jpg"); if (track.getTrack().getInfo().isStream) eb.addField("Amount Played", "Issa livestream ;)", false); else eb.addField("Amount Played", GeneralUtils.getProgressBar(track), true) .addField("Time", String.format("%s / %s", FormatUtils.formatDuration(track.getTrack().getPosition()), FormatUtils.formatDuration(track.getTrack().getDuration())), false); ButtonGroup buttonGroup = new ButtonGroup(sender.getIdLong(), ButtonGroupConstants.SONG); buttonGroup.addButton(new ButtonGroup.Button("\u23EF", (owner, user, message1) -> { if (manager.hasPlayer(guild.getGuildId())) { if (manager.getPlayer(guild.getGuild().getId()).getPaused()) { if (getPermissions(channel).hasPermission(guild.getGuild().getMember(user), Permission.RESUME_COMMAND)) { manager.getPlayer(guild.getGuild().getId()).play(); } } else { if (getPermissions(channel).hasPermission(guild.getGuild().getMember(user), Permission.PAUSE_COMMAND)) { manager.getPlayer(guild.getGuild().getId()).setPaused(true); } } } })); buttonGroup.addButton(new ButtonGroup.Button("\u23F9", (owner, user, message1) -> { if (manager.hasPlayer(guild.getGuildId()) && getPermissions(channel).hasPermission(guild.getGuild().getMember(user), Permission.STOP_COMMAND)) { manager.getPlayer(guild.getGuildId()).stop(); } })); buttonGroup.addButton(new ButtonGroup.Button("\u23ED", (owner, user, message1) -> { if (getPermissions(channel).hasPermission(guild.getGuild().getMember(user), Permission.SKIP_COMMAND)) { Command cmd = FlareBot.getCommandManager().getCommand("skip", user); if (cmd != null) cmd.onCommand(user, guild, channel, message1, new String[0], guild.getGuild().getMember(user)); } })); buttonGroup.addButton(new ButtonGroup.Button("\uD83D\uDD01", (ownerID, user, message1) -> { updateSongMessage(user, message1, message1.getTextChannel()); })); ButtonUtil.sendButtonedMessage(channel, eb.build(), buttonGroup); } else { channel.sendMessage(MessageUtils.getEmbed(sender) .addField("Current song", "**No song playing right now!**", false) .build()).queue(); } }