discord4j.core.event.domain.guild.GuildCreateEvent Java Examples
The following examples show how to use
discord4j.core.event.domain.guild.GuildCreateEvent.
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: GuildCreateListener.java From Shadbot with GNU General Public License v3.0 | 5 votes |
@Override public Mono<Void> execute(GuildCreateEvent event) { return Mono.fromRunnable(() -> { final long guildId = event.getGuild().getId().asLong(); final int memberCount = event.getGuild().getMemberCount(); DEFAULT_LOGGER.debug("{Guild ID: {}} Connected ({} users)", guildId, memberCount); CacheManager.getInstance().getGuildOwnersCache().save(event.getGuild().getId(), event.getGuild().getOwnerId()); }); }
Example #2
Source File: ReadyListener.java From KaellyBot with GNU General Public License v3.0 | 5 votes |
public void onReady(DiscordClient client) { if (!isReadyOnce.containsKey(client)) { long time = System.currentTimeMillis(); LOG.info("Ajout des différents listeners..."); client.getEventDispatcher().on(GuildCreateEvent.class) .subscribe(guildCreateEvent -> guildCreateListener.onReady(client, guildCreateEvent)); client.getEventDispatcher().on(GuildDeleteEvent.class) .subscribe(guildDeleteEvent -> guildLeaveListener.onReady(guildDeleteEvent)); client.getEventDispatcher().on(GuildUpdateEvent.class) .subscribe(guildUpdateEvent -> guildUpdateListener.onReady(guildUpdateEvent)); client.getEventDispatcher().on(TextChannelDeleteEvent.class) .subscribe(textChannelDeleteEvent -> channelDeleteListener.onReady(textChannelDeleteEvent)); LOG.info("Présence mise à jour..."); // Joue à... client.updatePresence(Presence.online(Activity.watching(Constants.discordInvite))).subscribe(); LOG.info("Ecoute des flux RSS du site Dofus..."); RSSFinder.start(); LOG.info("Lancement du calendrier Almanax..."); AlmanaxCalendar.start(); LOG.info("Connexion à l'API Twitter..."); TwitterFinder.start(); LOG.info("Ecoute des messages..."); client.getEventDispatcher().on(MessageCreateEvent.class) .subscribe(event -> messageListener.onReady(event)); isReadyOnce.put(client, true); LOG.info("Mise en place des ressources en " + (System.currentTimeMillis() - time) + "ms"); } }
Example #3
Source File: GuildCreateListener.java From Shadbot with GNU General Public License v3.0 | 4 votes |
@Override public Class<GuildCreateEvent> getEventType() { return GuildCreateEvent.class; }
Example #4
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); } }