本文整理汇总了Java中net.dv8tion.jda.core.entities.MessageEmbed类的典型用法代码示例。如果您正苦于以下问题:Java MessageEmbed类的具体用法?Java MessageEmbed怎么用?Java MessageEmbed使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MessageEmbed类属于net.dv8tion.jda.core.entities包,在下文中一共展示了MessageEmbed类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doCommand
import net.dv8tion.jda.core.entities.MessageEmbed; //导入依赖的package包/类
@Override
protected void doCommand(CommandEvent event)
{
EmbedBuilder builder = new EmbedBuilder();
builder.setColor(event.getSelfMember().getColor());
builder.setTitle("Server Traffic");
builder.addField(new MessageEmbed.Field("Traffic", MDCBot.trafficManager.getTrafficData().getRatio() + "/10", true));
if(event.getArgs().equalsIgnoreCase("details"))
{
builder.addField(new MessageEmbed.Field("Current ratio", String.valueOf(MDCBot.trafficManager.getTrafficData().getRatio()), true));
builder.addField(new MessageEmbed.Field("Max ratio", String.valueOf(TrafficManagerKt.getMaxRatio()), true));
builder.addField(new MessageEmbed.Field("#Messages", String.valueOf(MDCBot.trafficManager.getTrafficData().getMessages()), true));
builder.addField(new MessageEmbed.Field("#Users", String.valueOf(MDCBot.trafficManager.getTrafficData().getPlayers()), true));
}
reply(event, builder.build());
}
示例2: action
import net.dv8tion.jda.core.entities.MessageEmbed; //导入依赖的package包/类
@Override
public void action(String prefix, String[] args, MessageReceivedEvent event)
{
Guild guild = event.getGuild();
List<String> scheduleIds = Main.getScheduleManager().getSchedulesForGuild(guild.getId());
// build output main body
String content = "";
for(String sId : scheduleIds)
{
content += "<#" + sId + "> - has " + Main.getEntryManager().getEntriesFromChannel(sId).size() + " events\n";
}
String title = "Schedules on " + guild.getName(); // title for embed
String footer = scheduleIds.size() + " schedule(s)"; // footer for embed
// build embed
MessageEmbed embed = new EmbedBuilder()
.setDescription(content)
.setTitle(title)
.setFooter(footer, null).build();
Message message = new MessageBuilder().setEmbed(embed).build(); // build message
MessageUtilities.sendMsg(message, event.getTextChannel(), null); // send message
}
示例3: run
import net.dv8tion.jda.core.entities.MessageEmbed; //导入依赖的package包/类
public Result run(String[] args, MessageReceivedEvent e) {
//Send a request to Mojang
String payload = "{\"metricKeys\":[\"item_sold_minecraft\",\"prepaid_card_redeemed_minecraft\"]}";
String request = RequestUtils.post("https://api.mojang.com/orders/statistics", payload);
if (request == null) {
return new Result(Outcome.ERROR, ":x: The Mojang API could not be reached.");
}
//Extract JSON data
JSONObject sales = new JSONObject(request);
int total = sales.getInt("total");
int last24h = sales.getInt("last24h");
double velocity = 3600 * sales.getDouble("saleVelocityPerSeconds");
//Build and format message
String m = "**Total Sales:** " + format(total) +
"\n" + "**Last 24 Hours:** " + format(last24h) +
"\n" + "**Sales Per Hour:** " + format(velocity);
MessageEmbed me = MessageUtils.embedMessage("Minecraft Sales", null, m, Color.GREEN);
return new Result(Outcome.SUCCESS, me);
}
示例4: run
import net.dv8tion.jda.core.entities.MessageEmbed; //导入依赖的package包/类
public Result run(String[] args, MessageReceivedEvent e) {
//Iterate over commands
String m = "";
for (Command c : Registry.commands) {
CommandInfo ci = c.getInfo();
if ("".equals(ci.name)) {continue;}
//Build message
m += "`" + Config.getPrefix() + ci.name + "` **-** " + c.uses + "\n";
}
m = m.substring(0, m.length() - 1);
String title = "Command usage for " + DateUtils.getUptime();
MessageEmbed me = MessageUtils.embedMessage(title, null, m, Color.GREEN);
return new Result(Outcome.SUCCESS, me);
}
示例5: buildGoLiveEmbed
import net.dv8tion.jda.core.entities.MessageEmbed; //导入依赖的package包/类
public static MessageEmbed buildGoLiveEmbed(BTBBeamChannel channel) {
return new EmbedBuilder()
.setTitle(String.format("%s is now live!", channel.user.username),
String.format("https://beam.pro/%s", channel.user.username))
.setThumbnail(String.format("https://beam.pro/api/v1/users/%d/avatar?_=%d", channel.user.id,
new Random().nextInt()))
.setDescription(StringUtils.isBlank(channel.user.bio) ? "No bio" : channel.user.bio)
.addField(channel.name, channel.type == null ? "No game selected" : channel.type.name, false)
.addField("Followers", Integer.toString(channel.numFollowers), true)
.addField("Views", Integer.toString(channel.viewersTotal), true)
.addField("Rating", Enums.serializedName(channel.audience), true)
.setImage(String.format("https://thumbs.beam.pro/channel/%d.small.jpg?_=%d", channel.id,
new Random().nextInt()))
.setFooter("Beam.pro", CommandHelper.BEAM_LOGO_URL).setTimestamp(Instant.now())
.setColor(CommandHelper.COLOR).build();
}
示例6: replyAndKeep
import net.dv8tion.jda.core.entities.MessageEmbed; //导入依赖的package包/类
@Override
public void replyAndKeep(Config config, CommandEvent commandEvent, String message) {
if (config != null && config.getReplyInDmWhenPossible()) {
commandEvent.replyInDM(message);
commandEvent.reactSuccess();
handleOriginMessage(commandEvent);
} else {
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setAuthor(null, null, null);
embedBuilder.setTitle(null);
embedBuilder.setDescription(message);
final MessageEmbed messageEmbed = embedBuilder.build();
replyThenDeleteFeedbackAndOriginMessageAfterXTime(commandEvent,
messageEmbed, BotServerMain.timeToRemoveFeedbackInSeconds * 3, TimeUnit.SECONDS);
}
}
示例7: doCommand
import net.dv8tion.jda.core.entities.MessageEmbed; //导入依赖的package包/类
@Override
public boolean doCommand(MessageReceivedEvent message, BotContext context, String query) {
LocalMember localMember = memberService.getOrCreate(message.getMember());
MemberBio bio = bioRepository.findByMember(localMember);
if (bio == null) {
bio = new MemberBio();
bio.setMember(localMember);
}
if (StringUtils.isEmpty(query)) {
EmbedBuilder builder = messageService.getBaseEmbed(true);
if (StringUtils.isNotEmpty(bio.getBio())) {
builder.appendDescription(bio.getBio()).appendDescription("\n\n--------\n");
}
builder.appendDescription(messageService.getMessage("discord.command.bio.info",
context.getConfig().getPrefix()));
messageService.sendMessageSilent(message.getChannel()::sendMessage, builder.build());
return true;
}
bio.setBio("-".equals(query) ? null : CommonUtils.trimTo(query.trim(), MessageEmbed.TEXT_MAX_LENGTH - 500));
bioRepository.save(bio);
return ok(message, "discord.command.bio.updated", context.getConfig().getPrefix());
}
示例8: renderArticle
import net.dv8tion.jda.core.entities.MessageEmbed; //导入依赖的package包/类
private MessageEmbed renderArticle(Article article, boolean redirected) {
if (article == null || StringUtils.isEmpty(article.getRevisionId())) {
return null;
}
EngProcessedPage processedPage = processedPage(article);
String redirect = lookupRedirect(processedPage);
if (redirect != null) {
if (redirected) {
return null;
}
return renderArticle(getArticle(redirect), true);
}
EmbedBuilder embedBuilder = messageService.getBaseEmbed();
try {
embedBuilder.setTitle(article.getTitle(), WIKI_URL + UriUtils.encode(article.getTitle(), "UTF-8"));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
TextConverter converter = new TextConverter(config, embedBuilder);
return (MessageEmbed) converter.go(processedPage.getPage());
}
示例9: reply
import net.dv8tion.jda.core.entities.MessageEmbed; //导入依赖的package包/类
@Override
public void reply(Config config, CommandEvent commandEvent, String message, int numberOfSecondsBeforeRemove,
LocaleService localeService) {
Validate.isTrue(numberOfSecondsBeforeRemove > 5);
if (config != null && config.getReplyInDmWhenPossible()) {
commandEvent.replyInDM(message);
commandEvent.reactSuccess();
handleOriginMessage(commandEvent);
} else {
commandEvent.reactSuccess();
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setAuthor(null, null, null);
embedBuilder.setTitle(null);
embedBuilder.setDescription(message);
final String msgRemoveText = localeService.getMessageFor(LocaleService.KEEP_CHAT_CLEAN,
localeService.getLocaleForUser(commandEvent.getAuthor()), "" +
numberOfSecondsBeforeRemove);
embedBuilder.setFooter(msgRemoveText, null);
final MessageEmbed messageEmbed = embedBuilder.build();
replyThenDeleteFeedbackAndOriginMessageAfterXTime(commandEvent, messageEmbed, numberOfSecondsBeforeRemove,
TimeUnit.SECONDS);
}
}
示例10: bot
import net.dv8tion.jda.core.entities.MessageEmbed; //导入依赖的package包/类
private static MessageEmbed bot(GuildMessageReceivedEvent event, BotInfo[] infos) {
if (infos.length == 0 || infos[0] == null) {
return new EmbedBuilder()
.setDescription("No bot that matches the specified criteria found")
.setColor(event.getMember().getColor())
.setTitle("No bot found")
.build();
}
BotInfo info = infos[0];
return new EmbedBuilder()
.setAuthor(info.getUsername() + "#" + info.getDiscriminatorString(), null,
"https://images.discordapp.net/avatars/" + info.getId() + "/" +
(info.getAvatar() == null ? info.getDefaultAvatar() : info.getAvatar()) + ".png?size=512"
)
.setDescription("\u200D")
.setTitle("Bot Info")
.addField("ID", "" + info.getId(), true)
.addField("Prefix",
info.getPrefix().replace("*", "\\*").replace("_", "\\_").replace("~", "\\~").replace("`", "\\`"),
true)
.addField("Invite", "[Click here](" + info.getInvite() + ")", true)
.addField("Owner" + (info.getOwners().length == 1 ? "" : "s"),
Arrays.stream(info.getOwners()).mapToObj(id -> event.getGuild().getMemberById(id) != null ? "<@" + id + ">" : getName(id)).collect(Collectors.joining("\n")),
true)
.addField("Short Description", info.getShortDescription(), false)
.addField("Shard Count", info.getShardCount() == -1 ? "Unavailable" : "" + info.getShardCount(), true)
.addField("Guild Count", info.getServerCount() == -1 ? "Unavailable" : "" + info.getServerCount(), true)
.addField("Upvotes", "" + info.getPoints(), true)
.addField("Lib", info.getLib(), true)
.addField("Certified", "" + info.isCertified(), true)
.setThumbnail(
"https://images.discordapp.net/avatars/" + info.getId() + "/" +
(info.getAvatar() == null ? info.getDefaultAvatar() : info.getAvatar()) + ".png?size=512"
)
.setColor(event.getMember().getColor())
.setFooter(infos.length > 1 ? "Best match out of " + infos.length : "Only bot that matches", null)
.build();
}
示例11: sendAndWaitMessage
import net.dv8tion.jda.core.entities.MessageEmbed; //导入依赖的package包/类
@Override
public Message sendAndWaitMessage(MessageEmbed message_) {
try {
if (isPrivate()) {
return Util.sendAndWaitPrivateMessage(message.getAuthor(), message_);
} else {
return message.getChannel().sendMessage(message_).complete();
}
} catch (Exception ex) {
if (DEBUG) {
ex.printStackTrace();
}
return null;
}
}
示例12: sendPrivateMessage
import net.dv8tion.jda.core.entities.MessageEmbed; //导入依赖的package包/类
public static final boolean sendPrivateMessage(User user, MessageEmbed message) {
try {
final PrivateChannel privateChannel = user.openPrivateChannel().complete();
privateChannel.sendMessage(message).queue();
privateChannel.close();
return true;
} catch (Exception ex) {
System.err.println(ex);
return false;
}
}
示例13: sendAndWaitPrivateMessage
import net.dv8tion.jda.core.entities.MessageEmbed; //导入依赖的package包/类
public static final Message sendAndWaitPrivateMessage(User user, MessageEmbed message) {
try {
final PrivateChannel privateChannel = user.openPrivateChannel().complete();
final Message temp = privateChannel.sendMessage(message).complete();
privateChannel.close();
return temp;
} catch (Exception ex) {
System.err.println(ex);
return null;
}
}
示例14: embedMessageToString
import net.dv8tion.jda.core.entities.MessageEmbed; //导入依赖的package包/类
public static final String embedMessageToString(MessageEmbed message) {
if (message == null) {
return "";
}
final StringBuilder temp = new StringBuilder();
temp.append("[EmbedType: ").append(message.getType()).append("] ");
if (message.getColor() != null) {
temp.append("[Color: #").append(Integer.toHexString(message.getColor().getRGB()).substring(2)).append(", Alpha: ").append(Integer.toHexString(message.getColor().getRGB()).substring(0, 2)).append("] ");
} else {
temp.append("[Color: null] ");
}
temp.append("[Title: ").append(message.getTitle()).append("] ");
temp.append("[Description: ").append(message.getDescription()).append("] ");
if (message.getThumbnail() != null) {
temp.append("[").append(String.format("Thumbnail: %s (W: %d, H: %d)", message.getThumbnail().getProxyUrl(), message.getThumbnail().getWidth(), message.getThumbnail().getHeight())).append("] ");
}
if (message.getImage() != null) {
temp.append("[").append(String.format("Image: %s (W: %d, H: %d)", message.getImage().getProxyUrl(), message.getImage().getWidth(), message.getImage().getHeight())).append("] ");
}
if (message.getSiteProvider() != null) {
temp.append("[SiteProvider: ").append(message.getSiteProvider().getName()).append(" (").append(message.getSiteProvider().getUrl()).append(")] ");
}
if (message.getUrl() != null) {
temp.append("[Url: ").append(message.getUrl()).append(")] ");
}
if (message.getVideoInfo() != null) {
temp.append("[").append(String.format("VideoInfo: %s (W: %d, H: %d)", message.getVideoInfo().getUrl(), message.getVideoInfo().getWidth(), message.getVideoInfo().getHeight())).append("] ");
}
temp.append("[").append(message.getFields().stream().map((field) -> String.format("[%s; %s; %b]", field.getName(), field.getValue(), field.isInline())).collect(Collectors.joining(", "))).append("] ");
if (message.getFooter() != null) {
temp.append("[Footer: ").append(message.getFooter().getText()).append(" (").append(message.getFooter().getProxyIconUrl()).append(")] ");
}
return temp.toString();
}
示例15: generateMessage
import net.dv8tion.jda.core.entities.MessageEmbed; //导入依赖的package包/类
public static final MessageEmbed generateMessage(boolean live, boolean ip) {
final EmbedBuilder builder = Standard.getMessageEmbed(Color.YELLOW, Standard.toBold((live ? "Live " : "") + "System Information"))
.addField(String.format("%s Version", Standard.STANDARD_NAME), Standard.VERSION, false)
.addField("Java Version", System.getProperty("java.version"), false);
if (ip) {
builder.addField("IP Address", NetworkUtil.getIPAddress(), false);
}
builder.addField("CPU Cores available", "" + Runtime.getRuntime().availableProcessors(), false)
.addField("Max Memory", getMemory(Runtime.getRuntime().maxMemory()), false)
.addField("Total Memory", getMemory(Runtime.getRuntime().totalMemory()), false)
.addField("Free Memory", getMemory(Runtime.getRuntime().freeMemory()), false)
.addField("Local Server Time", Standard.STANDARD_DATE_TIME_FORMATTER.format(LocalDateTime.now()), false)
.addField("Converted Time", Standard.STANDARD_DATE_TIME_FORMATTER.format(LocalDateTime.now(Standard.getZoneId())), false);
return builder.build();
}