private static Collection<? extends Channel> getChannelsOfType(Guild guild, ChannelType type) { switch(type) { case TEXT: return guild.getTextChannels(); case VOICE: return guild.getVoiceChannels(); case CATEGORY: return guild.getCategories(); default: throw new IllegalArgumentException("Cannot order specified channel type " + type); } } }
/** * Gets the first channel in a guild where the bot has permission to write * * @param guild the guild to search in * @return TextChannel || null */ public static TextChannel findFirstWriteableChannel(Guild guild) { for (TextChannel channel : guild.getTextChannels()) { if (channel.canTalk()) { return channel; } } return null; }
/** * find a text channel by name * * @param guild the guild to search in * @param channelName the channel to search for * @return TextChannel || null */ public static TextChannel findChannel(Guild guild, String channelName) { for (TextChannel channel : guild.getTextChannels()) { if (channel.getName().equalsIgnoreCase(channelName)) { return channel; } } return null; }
.stream().filter(member -> member.getUser().isBot()).count(); counter.put("textChannels", guildById.getTextChannels().size()); counter.put("voiceChannels", guildById.getVoiceChannels().size()); counter.put("members", guildById.getMembers().size());
public void updateChannelData(Guild guild) { try { avaire.getDatabase().newQueryBuilder(Constants.GUILD_TABLE_NAME) .useAsync(true) .where("id", guild.getId()) .update(statement -> { statement.set("channels_data", GuildController.buildChannelData(guild.getTextChannels()), true); }); } catch (SQLException e) { e.printStackTrace(); } }
/** * This will go through all the channels in a guild, if there is no permission override or it doesn't block message write then deny it. * * @param muteRole This is the muted role of the server, the role which will have MESSAGE_WRITE denied. */ private void handleMuteChannels(Role muteRole) { getGuild().getTextChannels().forEach(channel -> { if (!getGuild().getSelfMember().hasPermission(channel, Permission.MANAGE_PERMISSIONS)) return; if (channel.getPermissionOverride(muteRole) != null && !channel.getPermissionOverride(muteRole).getDenied().contains(Permission.MESSAGE_WRITE)) channel.getPermissionOverride(muteRole).getManager().deny(Permission.MESSAGE_WRITE).queue(); else if (channel.getPermissionOverride(muteRole) == null) channel.createPermissionOverride(muteRole).setDeny(Permission.MESSAGE_WRITE).queue(); }); }
b.setColor(GfxUtil.getAverageColor(guild.getIconUrl())); b.addField("Members", String.format("%s online\n%s in total", online, guild.getMembers().size()), true); b.addField("Channels", String.format("%s text channels\n%s voice channels", guild.getTextChannels().size(), guild.getVoiceChannels().size()), true); b.addField("Created by", String.format("%s\\#%s", guild.getOwner().getUser().getName(), guild.getOwner().getUser().getDiscriminator()), true); b.addField("My prefix", String.format("`%s`", DisUtil.getCommandPrefix(guild)), true);
eb.addField("Channels", "**Text**\n" + "Total: " + guild.getTextChannels().size() + "\n" + "\n" + "**Voice**\n" +
@Override public boolean onCommand(CommandMessage context, String[] args) { Guild guild = context.getGuild(); Carbon time = Carbon.createFromOffsetDateTime(guild.getCreationTime()); PlaceholderMessage placeholderMessage = context.makeEmbeddedMessage(getRoleColor(guild.getSelfMember().getRoles()), new MessageEmbed.Field(context.i18n("fields.id"), guild.getId(), true), new MessageEmbed.Field(context.i18n("fields.owner"), guild.getOwner().getUser().getName() + "#" + guild.getOwner().getUser().getDiscriminator(), true), new MessageEmbed.Field(context.i18n("fields.textChannels"), NumberUtil.formatNicely(guild.getTextChannels().size()), true), new MessageEmbed.Field(context.i18n("fields.voiceChannels"), NumberUtil.formatNicely(guild.getVoiceChannels().size()), true), new MessageEmbed.Field(context.i18n("fields.members"), NumberUtil.formatNicely(guild.getMembers().size()), true), new MessageEmbed.Field(context.i18n("fields.roles"), NumberUtil.formatNicely(guild.getRoles().size()), true), new MessageEmbed.Field(context.i18n("fields.region"), guild.getRegion().getName(), true), new MessageEmbed.Field(context.i18n("fields.createdAt"), time.format(context.i18n("timeFormat")) + "\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( context.i18n("fields.emojis", guild.getEmotes().size()), guild.getEmotes().stream() .map(emote -> emote.getName() + (hasMany ? "" : " " + emote.getAsMention())) .collect(Collectors.joining(", ")), true )); } placeholderMessage.requestedBy(context.getMember()).queue(); return true; }
.set("name", guild.getName(), true) .set("roles_data", buildRoleData(guild.getRoles()), true) .set("channels_data", buildChannelData(guild.getTextChannels()), true);
for (TextChannel channel : guild.getTextChannels()) { if (channel.canTalk()) { outChannel = channel;