本文整理汇总了Java中net.dv8tion.jda.core.entities.Message.getGuild方法的典型用法代码示例。如果您正苦于以下问题:Java Message.getGuild方法的具体用法?Java Message.getGuild怎么用?Java Message.getGuild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.dv8tion.jda.core.entities.Message
的用法示例。
在下文中一共展示了Message.getGuild方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import net.dv8tion.jda.core.entities.Message; //导入方法依赖的package包/类
@Override
protected Message execute(CommandManager.ParsedCommandInvocation parsedCommandInvocation, UserPermissions userPermissions) {
Message message = parsedCommandInvocation.getMessage();
Guild guild = message.getGuild();
TextChannel channel = message.getTextChannel();
StringBuilder rawRoles = new StringBuilder();
guild.getRoles().forEach(r -> rawRoles.append(r.getName()).append(", "));
StringBuilder roles = new StringBuilder(rawRoles.toString());
roles.replace(rawRoles.lastIndexOf(","), roles.lastIndexOf(",") + 1, "" );
EmbedBuilder serverInfo = new EmbedBuilder();
serverInfo.setColor(Colors.COLOR_PRIMARY);
serverInfo.setTitle(":desktop: Serverinfo of " + guild.getName());
serverInfo.setThumbnail(guild.getIconUrl());
serverInfo.addField("ID", "`" + guild.getId() + "`", false);
serverInfo.addField("Guildname", "`" + guild.getName() + "`", false);
serverInfo.addField("Server region", guild.getRegion().toString(), false);
serverInfo.addField("Members", String.valueOf(guild.getMembers().size()), false);
serverInfo.addField("Textchannels", String.valueOf(guild.getTextChannels().size()), false);
serverInfo.addField("Voicechannels", String.valueOf(guild.getVoiceChannels().size()), false);
serverInfo.addField("Roles", String.valueOf(guild.getRoles().size()) + "\n ```" + roles.toString() + "```", false);
serverInfo.addField("Server owner", guild.getOwner().getUser().getName() + "#" + guild.getOwner().getUser().getDiscriminator(), false);
serverInfo.addField("Server icon url", guild.getIconUrl(), false);
serverInfo.addField("Server Creation Date", guild.getCreationTime().format(DateTimeFormatter.ISO_DATE_TIME), false);
return new MessageBuilder().setEmbed(serverInfo.build()).build();
}
示例2: doYaThing
import net.dv8tion.jda.core.entities.Message; //导入方法依赖的package包/类
@Override
public void doYaThing(Message message) {
Guild guild = message.getGuild();
TextChannel channel = message.getTextChannel();
boolean exists = false;
Admin admin = null;
for (Admin a : admins) {
if (a.getGuild().equals(guild.getId())) {
exists = true;
admin = a;
}
}
System.out.println(exists);
try {
if (exists) {
channel.sendMessage("Your guild already has an Admin: " + admin.getAdmin()).complete();
} else {
admins.add(new Admin(message.getAuthor().getId(), guild.getId()));
FileHandler.writeToFile(admins);
channel.sendMessage("Admin of " + guild.getName() + " is " + message.getAuthor().getAsMention()).complete();
}
} catch (Exception e) {
//message.getTextChannel().sendMessage(e.getMessage()).complete();
System.out.println(e.getMessage());
log.log("ERROR: " + e.getCause() + " " + e.getMessage());
}
}
示例3: onCommand
import net.dv8tion.jda.core.entities.Message; //导入方法依赖的package包/类
@Override
public boolean onCommand(Message message, String[] args) {
Guild guild = message.getGuild();
Carbon time = Carbon.createFromOffsetDateTime(guild.getCreationTime());
PlaceholderMessage placeholderMessage = MessageFactory.makeEmbeddedMessage(message.getChannel(), getRoleColor(guild.getSelfMember().getRoles()),
new MessageEmbed.Field("ID", guild.getId(), true),
new MessageEmbed.Field("Owner", guild.getOwner().getUser().getName() + "#" + guild.getOwner().getUser().getDiscriminator(), true),
new MessageEmbed.Field("Text Channels", "" + guild.getTextChannels().size(), true),
new MessageEmbed.Field("Voice Channels", "" + guild.getVoiceChannels().size(), true),
new MessageEmbed.Field("Members", "" + guild.getMembers().size(), true),
new MessageEmbed.Field("Roles", "" + guild.getRoles().size(), true),
new MessageEmbed.Field("Region", guild.getRegion().getName(), true),
new MessageEmbed.Field("Created At", time.format("EEE, dd MMM yyyy HH:mm") + "\n*About " + shortenDiffForHumans(time) + "*", true)
).setTitle(guild.getName()).setThumbnail(guild.getIconUrl());
if (!guild.getEmotes().isEmpty()) {
boolean hasMany = guild.getEmotes().size() > 17;
placeholderMessage.addField(new MessageEmbed.Field(
String.format("Custom Emojis (%s)", guild.getEmotes().size()),
guild.getEmotes().stream()
.map(emote -> emote.getName() + (hasMany ? "" : " " + emote.getAsMention()))
.collect(Collectors.joining(", ")),
true
));
}
placeholderMessage.queue();
return true;
}
示例4: onCommand
import net.dv8tion.jda.core.entities.Message; //导入方法依赖的package包/类
@Override
public boolean onCommand(Message message, String[] args) {
if (args.length == 0) {
return sendErrorMessage(message, "Missing argument `message`, you must include a message.");
}
TextChannel feedbackChannel = avaire.getTextChannelById(DiscordConstants.FEEDBACK_CHANNEL_ID);
if (feedbackChannel == null) {
return sendErrorMessage(message, "Invalid feedback channel defined, the text channel could not be found!");
}
PlaceholderMessage placeholderMessage = MessageFactory.makeEmbeddedMessage(feedbackChannel)
.addField("Feedback", String.join(" ", args), false)
.addField("Channel", buildChannel(message.getChannel()), false)
.setFooter("Author ID: " + message.getAuthor().getId())
.setTimestamp(Instant.now());
placeholderMessage.setAuthor(
message.getAuthor().getName() + "#" + message.getAuthor().getDiscriminator(),
null,
message.getAuthor().getEffectiveAvatarUrl()
);
if (message.getChannelType().isGuild() && message.getGuild() != null) {
placeholderMessage.addField("Server", buildServer(message.getGuild()), false);
}
placeholderMessage.queue(newMessage -> {
MessageFactory.makeSuccess(message, "Successfully sent feedback <:tickYes:319985232306765825>").queue();
}, err -> {
AvaIre.getLogger().error("Failed to send feedback message: " + err.getMessage(), err);
MessageFactory.makeError(message, "Failed to send feedback message: " + err.getMessage()).queue();
});
return true;
}
示例5: generateCacheString
import net.dv8tion.jda.core.entities.Message; //导入方法依赖的package包/类
public String generateCacheString(Message message, MiddlewareStack stack) {
if (!this.equals(ThrottleType.USER) && message.getGuild() == null) {
return USER.generateCacheString(message, stack);
}
String cacheFingerprint = generateCacheFingerprint(stack);
switch (this) {
case USER:
return String.format(cache,
message.getGuild() == null ? "private" : message.getGuild().getId(),
message.getAuthor().getId(),
cacheFingerprint);
case CHANNEL:
return String.format(cache,
message.getGuild().getId(),
message.getChannel().getId(),
cacheFingerprint);
case GUILD:
return String.format(cache,
message.getGuild().getId(),
cacheFingerprint);
default:
return ThrottleType.USER.generateCacheString(message, stack);
}
}
示例6: execute
import net.dv8tion.jda.core.entities.Message; //导入方法依赖的package包/类
@Override
protected Message execute(CommandManager.ParsedCommandInvocation parsedCommandInvocation, UserPermissions userPermissions) {
Message message = parsedCommandInvocation.getMessage();
String[] args = parsedCommandInvocation.getArgs();
TextChannel channel = message.getTextChannel();
Guild guild = message.getGuild();
if(args.length == 0){
return new MessageBuilder().setEmbed(EmbedUtil.info("Usage", "search <query>").build()).build();
}
StringBuilder query = new StringBuilder();
for (String arg : args) {
query.append(arg);
}
StringBuilder textchannels = new StringBuilder();
StringBuilder voicechannels = new StringBuilder();
StringBuilder members = new StringBuilder();
StringBuilder roles = new StringBuilder();
Message mymsg = channel.sendMessage(new EmbedBuilder().setColor(Color.cyan).setDescription("Collecting textchannels ...").build()).complete();
guild.getTextChannels().forEach(i -> {
if(i.getName().toLowerCase().contains(query.toString().toLowerCase()))
textchannels.append(i.getName() + "(`" + i.getId() + "`)").append("\n");
});
mymsg.editMessage(new EmbedBuilder().setColor(Color.cyan).setDescription("Collecting voicechannels ...").build()).queue();
guild.getVoiceChannels().forEach(i -> {
if(i.getName().toLowerCase().contains(query.toString().toLowerCase()))
voicechannels.append(i.getName() + "(`" + i.getId() + "`)").append("\n");
});
mymsg.editMessage(new EmbedBuilder().setColor(Color.cyan).setDescription("Collecting users ...").build()).queue();
guild.getMembers().forEach(i -> {
if(i.getUser().getName().toLowerCase().contains(query.toString().toLowerCase()) || i.getEffectiveName().toLowerCase().contains(query.toString().toLowerCase()))
members.append(i.getUser().getName() + "(`" + i.getUser().getId() + "`)").append("\n");
});
mymsg.editMessage(new EmbedBuilder().setColor(Color.cyan).setDescription("Collecting roles ...").build()).queue();
guild.getRoles().forEach(i -> {
if(i.getName().toLowerCase().contains(query.toString().toLowerCase()))
roles.append(i.getName() + "(`" + i.getId() + "`)").append("\n");
});
mymsg.delete().queue();
try {
EmbedBuilder results = new EmbedBuilder()
.setColor(Color.green)
.addField("**Textchannels**", textchannels.toString(), false)
.addField("**Voicechannles**", voicechannels.toString(), false)
.addField("**Members**", members.toString(), false)
.addField("**Roles**", roles.toString(), false);
return new MessageBuilder().setEmbed(results.build()).build();
} catch (IllegalArgumentException ex){
return new MessageBuilder().setEmbed(EmbedUtil.error("Error!", "Too many results!").build()).build();
}
}