discord4j.core.object.entity.TextChannel Java Examples
The following examples show how to use
discord4j.core.object.entity.TextChannel.
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: GuildLeaveListener.java From KaellyBot with GNU General Public License v3.0 | 6 votes |
public void onReady(GuildDeleteEvent event) { try { Optional<Guild> optionalGuild = event.getGuild().map(guildEvent -> Guild.getGuild(guildEvent, false)); if (optionalGuild.isPresent()) { Guild guild = optionalGuild.get(); guild.removeToDatabase(); LOG.info("La guilde " + event.getGuildId().asString() + " - " + guild.getName() + " a supprimé " + Constants.name); ClientConfig.DISCORD() .flatMap(cli -> cli.getChannelById(Snowflake.of(Constants.chanReportID))) .filter(chan -> chan instanceof TextChannel) .map(chan -> (TextChannel) chan) .distinct() .flatMap(chan -> chan.createMessage("[LOSE] **" + optionalGuild.get().getName() + "**, -" + event.getGuild().map(discord4j.core.object.entity.Guild::getMemberCount) .orElse(OptionalInt.empty()).orElse(0) + " utilisateurs")) .subscribe(); } } catch(Exception e){ Reporter.report(e, event.getGuild().orElse(null)); LOG.error("onReady", e); } }
Example #2
Source File: SendNudeCommand.java From KaellyBot with GNU General Public License v3.0 | 6 votes |
@Override public void request(Message message, Matcher m, Language lg) { if (message.getChannel().blockOptional().map(chan -> chan instanceof PrivateChannel).orElse(false) || message.getChannel().blockOptional().map(chan -> ((TextChannel) chan).isNsfw()).orElse(false)){ message.getChannel().flatMap(chan -> chan.createEmbed(spec -> { spec.setTitle(Translator.getLabel(lg, "sendnude.title")) .setColor(PINK_COLOR) .setFooter(Translator.getLabel(lg, "sendnude.author") .replace("{author}", Nude.MOAM.getAuthor()) .replace("{position}", "1") .replace("{number}", "1"), null) .setImage(Nude.MOAM.getImage()); })).subscribe(); } else // Exception NSFW BasicDiscordException.NO_NSFW_CHANNEL.throwException(message, this, lg); }
Example #3
Source File: Main.java From lavaplayer with Apache License 2.0 | 6 votes |
private void onMessageReceived(MessageCreateEvent event) { Message message = event.getMessage(); message.getContent().ifPresent(it -> { MessageChannel channel = message.getChannel().block(); if (channel instanceof TextChannel) { String[] command = it.split(" ", 2); if ("~play".equals(command[0]) && command.length == 2) { loadAndPlay((TextChannel) channel, command[1]); } else if ("~skip".equals(command[0])) { skipTrack((TextChannel) channel); } } }); }
Example #4
Source File: ChannelUtils.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 5 votes |
/** * Checks if the specified channel exists. * * @param nameOrId The channel name or ID. * @param event The event received. * @return <code>true</code> if exists, else <code>false</code>. */ public static boolean channelExists(String nameOrId, MessageCreateEvent event) { if (nameOrId.contains("#")) nameOrId = nameOrId.replace("#", ""); for (TextChannel c : event.getGuild().block().getChannels().ofType(TextChannel.class).toIterable()) { if (c.getName().equalsIgnoreCase(nameOrId) || c.getId().asString().equals(nameOrId)) return true; } return false; }
Example #5
Source File: ChannelUtils.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 5 votes |
public static boolean channelExists(String nameOrId, Guild guild) { if (nameOrId.contains("#")) nameOrId = nameOrId.replace("#", ""); for (TextChannel c : guild.getChannels().ofType(TextChannel.class).toIterable()) { if (c.getName().equalsIgnoreCase(nameOrId) || c.getId().asString().equals(nameOrId)) return true; } return false; }
Example #6
Source File: ChannelUtils.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 5 votes |
/** * Gets the IChannel from its name. * * @param nameOrId The channel name or ID. * @param event The event received. * @return the IChannel if successful, else <code>null</code>. */ public static TextChannel getChannelFromNameOrId(String nameOrId, MessageCreateEvent event) { if (nameOrId.contains("#")) nameOrId = nameOrId.replace("#", ""); for (TextChannel c : event.getGuild().block().getChannels().ofType(TextChannel.class).toIterable()) { if (c.getName().equalsIgnoreCase(nameOrId) || c.getId().asString().equals(nameOrId)) return c; } return null; }
Example #7
Source File: ChannelUtils.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 5 votes |
/** * Gets the IChannel from its name. * * @param nameOrId The channel name or ID. * @return the IChannel if successful, else <code>null</code>. */ public static TextChannel getChannelFromNameOrId(String nameOrId, Guild guild) { if (nameOrId.contains("#")) nameOrId = nameOrId.replace("#", ""); for (TextChannel c : guild.getChannels().ofType(TextChannel.class).toIterable()) { if (c.getName().equalsIgnoreCase(nameOrId) || c.getId().asString().equals(nameOrId)) return c; } return null; }
Example #8
Source File: ChannelUtils.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 5 votes |
/** * Gets the IChannel from its name. * * @param nameOrId The channel name or ID. * @return the IChannel if successful, else <code>null</code>. */ public static String getChannelNameFromNameOrId(String nameOrId, Guild guild) { if (nameOrId.contains("#")) nameOrId = nameOrId.replace("#", ""); for (TextChannel c : guild.getChannels().ofType(TextChannel.class).toIterable()) { if (c.getName().equalsIgnoreCase(nameOrId) || c.getId().asString().equals(nameOrId)) return c.getName(); } return "ERROR"; }
Example #9
Source File: Main.java From lavaplayer with Apache License 2.0 | 5 votes |
private void sendMessageToChannel(TextChannel channel, String message) { try { channel.createMessage(message).block(); } catch (Exception e) { log.warn("Failed to send message {} to {}", message, channel.getName(), e); } }
Example #10
Source File: WebChannel.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 5 votes |
public WebChannel fromChannel(TextChannel c, GuildSettings settings) { id = c.getId().asLong(); name = c.getName(); discalChannel = settings.getDiscalChannel().equalsIgnoreCase(String.valueOf(id)); return this; }
Example #11
Source File: Main.java From lavaplayer with Apache License 2.0 | 5 votes |
private void loadAndPlay(TextChannel channel, final String trackUrl) { GuildMusicManager musicManager = getGuildAudioPlayer(channel.getGuild().block()); playerManager.loadItemOrdered(musicManager, trackUrl, new AudioLoadResultHandler() { @Override public void trackLoaded(AudioTrack track) { sendMessageToChannel(channel, "Adding to queue " + track.getInfo().title); play(channel.getGuild().block(), musicManager, track); } @Override public void playlistLoaded(AudioPlaylist playlist) { AudioTrack firstTrack = playlist.getSelectedTrack(); if (firstTrack == null) { firstTrack = playlist.getTracks().get(0); } sendMessageToChannel(channel, "Adding to queue " + firstTrack.getInfo().title + " (first track of playlist " + playlist.getName() + ")"); play(channel.getGuild().block(), musicManager, firstTrack); } @Override public void noMatches() { sendMessageToChannel(channel, "Nothing found by " + trackUrl); } @Override public void loadFailed(FriendlyException exception) { sendMessageToChannel(channel, "Could not play: " + exception.getMessage()); } }); }
Example #12
Source File: WebChannel.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 5 votes |
public WebChannel fromChannel(TextChannel c, GuildSettings settings) { id = c.getId().asLong(); name = c.getName(); discalChannel = settings.getDiscalChannel().equalsIgnoreCase(String.valueOf(id)); return this; }
Example #13
Source File: ChannelUtils.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 5 votes |
/** * Gets the IChannel from its name. * * @param nameOrId The channel name or ID. * @return the IChannel if successful, else <code>null</code>. */ public static String getChannelNameFromNameOrId(String nameOrId, Guild guild) { if (nameOrId.contains("#")) nameOrId = nameOrId.replace("#", ""); for (TextChannel c : guild.getChannels().ofType(TextChannel.class).toIterable()) { if (c.getName().equalsIgnoreCase(nameOrId) || c.getId().asString().equals(nameOrId)) return c.getName(); } return "ERROR"; }
Example #14
Source File: ChannelUtils.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 5 votes |
/** * Gets the IChannel from its name. * * @param nameOrId The channel name or ID. * @return the IChannel if successful, else <code>null</code>. */ public static TextChannel getChannelFromNameOrId(String nameOrId, Guild guild) { if (nameOrId.contains("#")) nameOrId = nameOrId.replace("#", ""); for (TextChannel c : guild.getChannels().ofType(TextChannel.class).toIterable()) { if (c.getName().equalsIgnoreCase(nameOrId) || c.getId().asString().equals(nameOrId)) return c; } return null; }
Example #15
Source File: ChannelUtils.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 5 votes |
/** * Gets the IChannel from its name. * * @param nameOrId The channel name or ID. * @param event The event received. * @return the IChannel if successful, else <code>null</code>. */ public static TextChannel getChannelFromNameOrId(String nameOrId, MessageCreateEvent event) { if (nameOrId.contains("#")) nameOrId = nameOrId.replace("#", ""); for (TextChannel c : event.getGuild().block().getChannels().ofType(TextChannel.class).toIterable()) { if (c.getName().equalsIgnoreCase(nameOrId) || c.getId().asString().equals(nameOrId)) return c; } return null; }
Example #16
Source File: ChannelUtils.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 5 votes |
public static boolean channelExists(String nameOrId, Guild guild) { if (nameOrId.contains("#")) nameOrId = nameOrId.replace("#", ""); for (TextChannel c : guild.getChannels().ofType(TextChannel.class).toIterable()) { if (c.getName().equalsIgnoreCase(nameOrId) || c.getId().asString().equals(nameOrId)) return true; } return false; }
Example #17
Source File: ChannelUtils.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 5 votes |
/** * Checks if the specified channel exists. * * @param nameOrId The channel name or ID. * @param event The event received. * @return <code>true</code> if exists, else <code>false</code>. */ public static boolean channelExists(String nameOrId, MessageCreateEvent event) { if (nameOrId.contains("#")) nameOrId = nameOrId.replace("#", ""); for (TextChannel c : event.getGuild().block().getChannels().ofType(TextChannel.class).toIterable()) { if (c.getName().equalsIgnoreCase(nameOrId) || c.getId().asString().equals(nameOrId)) return true; } return false; }
Example #18
Source File: RSSFinder.java From KaellyBot with GNU General Public License v3.0 | 5 votes |
public synchronized static Map<String, RSSFinder> getRSSFinders(){ if (rssFinders == null){ rssFinders = new ConcurrentHashMap<>(); Connexion connexion = Connexion.getInstance(); Connection connection = connexion.getConnection(); try { PreparedStatement query = connection.prepareStatement("SELECT id_guild, id_chan, last_update FROM RSS_Finder"); ResultSet resultSet = query.executeQuery(); while (resultSet.next()){ String idChan = resultSet.getString("id_chan"); String idGuild = resultSet.getString("id_guild"); long lastUpdate = resultSet.getLong("last_update"); ClientConfig.DISCORD() .flatMap(client -> client.getChannelById(Snowflake.of(idChan))) .filter(channel -> channel instanceof TextChannel) .map(channel -> (TextChannel) channel) .collectList().blockOptional().orElse(Collections.emptyList()) .forEach(chan -> rssFinders.put(chan.getId().asString(), new RSSFinder(idGuild, chan.getId().asString(), lastUpdate))); } } catch (SQLException e) { Reporter.report(e); LOG.error("getRSSFinders", e); } } return rssFinders; }
Example #19
Source File: Translator.java From KaellyBot with GNU General Public License v3.0 | 5 votes |
/** * Détecte la langue majoritaire utilisée dans un salon textuel * @param channel Salon textuel à étudier * @return Langue majoritaire (ou Constants.defaultLanguage si non trouvée) */ public static Language detectLanguage(TextChannel channel){ Language result = Constants.defaultLanguage; Map<Language, LanguageOccurrence> languages = new HashMap<>(); for(Language lang : Language.values()) languages.put(lang, LanguageOccurrence.of(lang)); List<String> sources = getReformatedMessages(channel); for (String source : sources) languages.get(getLanguageFrom(source)).increment(); int longest = languages.entrySet().stream() .map(Map.Entry::getValue) .mapToInt(LanguageOccurrence::getOccurrence) .max() .orElse(-1); if (longest > 0){ List<Language> languagesSelected = languages.entrySet().stream() .map(Map.Entry::getValue) .filter(lo -> lo.getOccurrence() == longest) .map(lo -> lo.getLanguage()) .collect(Collectors.toList()); if (! languagesSelected.contains(result)) return languagesSelected.get(0); } return result; }
Example #20
Source File: GuildCreateListener.java From KaellyBot with GNU General Public License v3.0 | 4 votes |
public void onReady(DiscordClient client, GuildCreateEvent event) { try { if (!Guild.getGuilds().containsKey(event.getGuild().getId().asString())) { event.getGuild().getChannels() .filter(chan -> chan instanceof TextChannel) .map(chan -> (TextChannel) chan).take(1).flatMap(chan -> { Guild guild = new Guild(event.getGuild().getId().asString(), event.getGuild().getName(), Translator.detectLanguage(chan)); guild.addToDatabase(); Language lg = guild.getLanguage(); LOG.info("La guilde " + guild.getId() + " - " + guild.getName() + " a ajouté " + Constants.name); return event.getGuild().getOwner().flatMap(owner -> { String customMessage = Translator.getLabel(lg, "welcome.message") .replaceAll("\\{name}", Constants.name) .replaceAll("\\{game}", Constants.game.getName()) .replaceAll("\\{prefix}", Constants.prefixCommand) .replaceAll("\\{help}", HelpCommand.NAME) .replaceAll("\\{server}", new ServerCommand().getName()) .replaceAll("\\{lang}", new LanguageCommand().getName()) .replaceAll("\\{twitter}", new TwitterCommand().getName()) .replaceAll("\\{almanax-auto}", new AlmanaxAutoCommand().getName()) .replaceAll("\\{rss}", new RSSCommand().getName()) .replaceAll("\\{owner}", owner.getMention()) .replaceAll("\\{guild}", event.getGuild().getName()); return chan.getEffectivePermissions(client.getSelfId().orElse(null)) .flatMap(perm -> perm.contains(Permission.SEND_MESSAGES) ? chan.createMessage(customMessage) : event.getGuild().getOwner() .flatMap(Member::getPrivateChannel) .flatMap(ownerChan -> ownerChan.createMessage(customMessage))) .thenMany(ClientConfig.DISCORD() .flatMap(cli -> cli.getChannelById(Snowflake.of(Constants.chanReportID))) .filter(channel -> channel instanceof TextChannel) .map(channel -> (TextChannel) channel) .distinct() .flatMap(channel -> channel.createMessage("[NEW] **" + event.getGuild().getName() + "** (" + guild.getLanguage().getAbrev() + "), +" + event.getGuild().getMemberCount().orElse(0) + " utilisateurs"))) .collectList(); }); }).subscribe(); } } catch(Exception e){ Reporter.report(e, event.getGuild()); LOG.error("onReady", e); } }
Example #21
Source File: MessageManager.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 4 votes |
public static void sendMessageAsync(String message, TextChannel channel) { channel.createMessage(spec -> spec.setContent(message)).subscribe(); }
Example #22
Source File: MessageManager.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 4 votes |
public static Message sendMessageSync(String message, Consumer<EmbedCreateSpec> embed, TextChannel channel) { return channel.createMessage(spec -> spec.setContent(message).setEmbed(embed)).block(); }
Example #23
Source File: MessageManager.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 4 votes |
public static Message sendMessageSync(Consumer<EmbedCreateSpec> embed, TextChannel channel) { return channel.createMessage(spec -> spec.setEmbed(embed)).block(); }
Example #24
Source File: MessageManager.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 4 votes |
public static Message sendMessageSync(String message, TextChannel channel) { return channel.createMessage(spec -> spec.setContent(message)).block(); }
Example #25
Source File: MessageManager.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 4 votes |
public static void sendMessageAsync(String message, Consumer<EmbedCreateSpec> embed, TextChannel channel) { channel.createMessage(spec -> spec.setContent(message).setEmbed(embed)).subscribe(); }
Example #26
Source File: MessageManager.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 4 votes |
public static void sendMessageAsync(Consumer<EmbedCreateSpec> embed, TextChannel channel) { channel.createMessage(spec -> spec.setEmbed(embed)).subscribe(); }
Example #27
Source File: MessageManager.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 4 votes |
public static void sendMessageAsync(String message, TextChannel channel) { channel.createMessage(spec -> spec.setContent(message)).subscribe(); }
Example #28
Source File: Main.java From lavaplayer with Apache License 2.0 | 4 votes |
private void skipTrack(TextChannel channel) { GuildMusicManager musicManager = getGuildAudioPlayer(channel.getGuild().block()); musicManager.scheduler.nextTrack(); sendMessageToChannel(channel, "Skipped to next track."); }
Example #29
Source File: MessageManager.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 4 votes |
public static Message sendMessageSync(String message, Consumer<EmbedCreateSpec> embed, TextChannel channel) { return channel.createMessage(spec -> spec.setContent(message).setEmbed(embed)).block(); }
Example #30
Source File: MessageManager.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 4 votes |
public static Message sendMessageSync(Consumer<EmbedCreateSpec> embed, TextChannel channel) { return channel.createMessage(spec -> spec.setEmbed(embed)).block(); }