當前位置: 首頁>>代碼示例>>Java>>正文


Java MessageReceivedEvent.getGuild方法代碼示例

本文整理匯總了Java中net.dv8tion.jda.core.events.message.MessageReceivedEvent.getGuild方法的典型用法代碼示例。如果您正苦於以下問題:Java MessageReceivedEvent.getGuild方法的具體用法?Java MessageReceivedEvent.getGuild怎麽用?Java MessageReceivedEvent.getGuild使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net.dv8tion.jda.core.events.message.MessageReceivedEvent的用法示例。


在下文中一共展示了MessageReceivedEvent.getGuild方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: action

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入方法依賴的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
}
 
開發者ID:notem,項目名稱:Saber-Bot,代碼行數:26,代碼來源:SchedulesCommand.java

示例2: doCommand

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入方法依賴的package包/類
@Override
public boolean doCommand(MessageReceivedEvent message, BotContext context, String query) {
    Guild guild = message.getGuild();

    EmbedBuilder builder = messageService.getBaseEmbed();
    builder.setTitle(messageService.getMessage("discord.command.server.title", guild.getName()));
    builder.setThumbnail(guild.getIconUrl());
    builder.setFooter(messageService.getMessage("discord.command.info.identifier", guild.getId()), null);

    builder.addField(getMemberListField(guild));
    builder.addField(getChannelListField(guild));
    builder.addField(getVerificationLevel(guild));
    builder.addField(getRegion(guild));
    builder.addField(getOwner(guild));
    builder.addField(getCreatedAt(guild));

    messageService.sendMessageSilent(message.getChannel()::sendMessage, builder.build());
    return true;
}
 
開發者ID:GoldRenard,項目名稱:JuniperBotJ,代碼行數:20,代碼來源:ServerInfoCommand.java

示例3: handle

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入方法依賴的package包/類
/**
 * The whole command handling method.
 *
 * @param event The event to handle.
 */
@SubscribeEvent
public void handle(MessageReceivedEvent event) {
    if (event.getGuild() == null) return;
    if (!event.getGuild().getId().equals(Config.SERVER)) return;
    if (!event.getMessage().getContent().startsWith(prefix)) return;

    String[] splitContent = event.getMessage().getContent().replace(prefix, "").split(" ");
    if (!commands.containsKey(splitContent[0])) return;

    Command command = commands.get(splitContent[0]);
    RegisterCommand annotation = command.getCommandAnnotation();

    if (event.getChannelType().equals(ChannelType.PRIVATE) && !annotation.directMessages()) return;
    if (event.getChannelType().equals(ChannelType.TEXT) && !annotation.channelMessages()) return;
    if (event.getAuthor().equals(event.getJDA().getSelfUser()) && !annotation.allowSelf()) return;
    if (!event.getAuthor().equals(event.getJDA().getSelfUser()) && !annotation.allowOthers()) return;

    ZLevels.async.submit(() -> invokeMethod(command, getParameters(splitContent, command, event.getMessage(),
            event.getJDA())));
}
 
開發者ID:ZP4RKER,項目名稱:zlevels,代碼行數:26,代碼來源:CommandHandler.java

示例4: sendEmotion

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入方法依賴的package包/類
private void sendEmotion(MessageReceivedEvent message, String emoji, String messageCode, Object... args) {
    try {
        if (message.getGuild() == null || PermissionUtil.checkPermission(message.getTextChannel(),
                message.getMember(), Permission.MESSAGE_ADD_REACTION)) {
            message.getMessage().addReaction(emoji).submit();
        } else if (StringUtils.isNotEmpty(messageCode)) {
            String text = messageService.getMessage(messageCode, args);
            messageService.sendMessageSilent(message.getChannel()::sendMessage, text);
        }
    } catch (Exception e) {
        LOGGER.error("Add emotion error", e);
    }
}
 
開發者ID:GoldRenard,項目名稱:JuniperBotJ,代碼行數:14,代碼來源:AbstractCommand.java

示例5: sendMessage

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入方法依賴的package包/類
@Override
public void sendMessage(MessageReceivedEvent event, MessageSender sender) {
    JDA jda = event.getJDA();
    if (event.getAuthor().isBot()) {
        return;
    }
    GuildConfig guildConfig = null;
    if (event.getChannelType().isGuild() && event.getGuild() != null) {
        guildConfig = configService.getOrCreate(event.getGuild());
    }

    String content = event.getMessage().getRawContent().trim();
    String prefix = guildConfig != null ? guildConfig.getPrefix() : configService.getDefaultPrefix();
    if (event.getMessage().isMentioned(jda.getSelfUser())) {
        String customMention = String.format("<@!%s>", jda.getSelfUser().getId());
        prefix = content.startsWith(customMention) ? customMention : jda.getSelfUser().getAsMention();
    }
    if (StringUtils.isNotEmpty(content) && content.startsWith(prefix) && content.length() <= MessageEmbed.TEXT_MAX_LENGTH) {
        String input = content.substring(prefix.length()).trim();
        String[] args = input.split("\\s+");
        if (args.length == 0) {
            return;
        }
        input = input.substring(args[0].length(), input.length()).trim();
        sender.sendCommand(event, input, args[0], guildConfig);
    }
}
 
開發者ID:GoldRenard,項目名稱:JuniperBotJ,代碼行數:28,代碼來源:CommandsServiceImpl.java

示例6: onMessage

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入方法依賴的package包/類
@SubscribeEvent
public void onMessage(MessageReceivedEvent event) {
    if (event.getGuild() == null) return;
    if (!event.getGuild().getId().equals(Config.SERVER)) return;
    if (event.getAuthor().isBot()) return;

    if (!spamFilter.contains(event.getAuthor().getId())) {
        if (event.getMessage().getContent().startsWith("-")) return;

        ZLevels.async.submit(() -> {
            UserData data = UserData.fromId(event.getAuthor().getId());

            if (data == null) {
                data = new UserData();
                data.setUserId(event.getAuthor().getId());
            }

            long randomXp = LevelsUtil.randomXp(10, 25);

            data.setTotalXp(data.getTotalXp() + randomXp);
            data.save();

            spamFilter.add(event.getAuthor().getId());

            new Timer().schedule(new TimerTask() {
                @Override
                public void run() {
                    spamFilter.remove(event.getAuthor().getId());
                }
            }, 1000 * 60);
        });
    }
}
 
開發者ID:ZP4RKER,項目名稱:zlevels,代碼行數:34,代碼來源:MessageSendListener.java

示例7: action

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入方法依賴的package包/類
@Override
public void action(String prefix, String[] args, MessageReceivedEvent event)
{
    // process any optional channel arguments
    List<String> channelIds = new ArrayList<>();
    for (String arg : args)
    {
        channelIds.add(arg.replaceAll("[^\\d]", ""));
    }

    Guild guild = event.getGuild();
    List<String> scheduleIds = Main.getScheduleManager().getSchedulesForGuild(guild.getId());
    if(!channelIds.isEmpty())
    {
        // filter the list of schedules
        scheduleIds = scheduleIds.stream().filter(channelIds::contains).collect(Collectors.toList());
    }

    // build the embed body content
    int count = 0;
    StringBuilder content = new StringBuilder();
    for(String sId : scheduleIds)
    {
        // for each schedule, generate a list of events scheduled
        Collection<ScheduleEntry> entries = Main.getEntryManager().getEntriesFromChannel(sId);
        if(!entries.isEmpty())
        {
            content.append("<#").append(sId).append("> ...\n");  // start a new schedule list
            while(!entries.isEmpty())
            {
                // find and remove the next earliest occurring event
                ScheduleEntry top = entries.toArray(new ScheduleEntry[entries.size()])[0];
                for(ScheduleEntry se : entries)
                {
                    if(se.getStart().isBefore(top.getStart())) top = se;
                }
                entries.remove(top);

                long timeTil = ZonedDateTime.now().until(top.getStart(), ChronoUnit.MINUTES);

                // create entry in the message for the event
                content.append(":id:``").append(ParsingUtilities.intToEncodedID(top.getId()))
                        .append("`` ~ **").append(top.getTitle()).append("** in *");
                if(timeTil < 120)
                    content.append(timeTil).append(" minutes*\n");
                else if(timeTil < 24*60)
                    content.append(timeTil / 60).append(" hours and ").append(timeTil % 60).append(" minutes*\n");
                else
                    content.append(timeTil / (60 * 24)).append(" days*\n");
                count++;     // iterate event counter
            }
            content.append("\n"); // end a schedule list
        }
    }

    String title = "Events on " + guild.getName();          // title for embed
    String footer = count + " event(s)";                    // footer for embed

    // build embed and message
    MessageEmbed embed = new EmbedBuilder()
                            .setFooter(footer, null)
                            .setTitle(title)
                            .setDescription(content.toString()).build();

    Message message = new MessageBuilder().setEmbed(embed).build();            // build message
    MessageUtilities.sendMsg(message, event.getTextChannel(), null);     // send message
}
 
開發者ID:notem,項目名稱:Saber-Bot,代碼行數:68,代碼來源:EventsCommand.java

示例8: playCommand

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入方法依賴的package包/類
private void playCommand(String user, String command, MessageReceivedEvent e)
{
	// If no user, find the default user from the admin property.
	if (user == null || user.isEmpty())
		user = properties.getProperty("admin");
	
	// Check if the sound exists in the library.
	Sound sound = library.getFile(command);
	if (sound == null)
	{
		log.warn("Could not find the requested sound. <" + command + ">");
		this.isLocked = false;
		return;
	}
	
	Guild guild = null;
	VoiceChannel voiceChannel = null;
	
	// If the channel is private, we've been direct messaged.
	if (e.isFromType(ChannelType.PRIVATE))
	{
		// if that is the case, we need to find the messaging user in our available guild.
		guild = getGuild(e.getAuthor());
		if (guild == null)
		{
			log.warn("Could not find requesting user's guild, aborting.");
			this.isLocked = false;
			return;
		}
		
		voiceChannel = getVoiceChannel(e.getAuthor(), guild);
		if (voiceChannel == null)
		{
			log.warn("Could not find requesting user's voice channel, aborting.");
			this.isLocked = false;
			return;
		}
	}
	else
	{
		// Otherwise, just grab the guild from the message event.
		guild = e.getGuild();
		if (guild == null)
		{
			log.warn("Could not find requesting user's guild, aborting.");
			this.isLocked = false;
			return;
		}
		
		// And grab the voice channel the same way.
		voiceChannel = e.getMember().getVoiceState().getChannel();
		if (voiceChannel == null)
		{
			log.warn("Could not find requesting user's voice channel, aborting.");
			this.isLocked = false;
			return;
		}
	}
	
	
	// Attempt to join the channel.
	if (joinChannel(voiceChannel, guild) == false)
	{
		log.warn("Could not join the requesting user's channel, aborting.");
		this.isLocked = false;
		return;
	}
	
	// Attempt to play the sound.
	if (playSound(command, guild, voiceChannel) == false)
	{
		log.warn("Could not play the sound requested.");
		leaveChannel(guild, voiceChannel);
	}
}
 
開發者ID:SegfaultError11,項目名稱:WeenieBot,代碼行數:76,代碼來源:WeenieBot.java

示例9: doCommand

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入方法依賴的package包/類
@Override
public boolean doCommand(MessageReceivedEvent message, BotContext context, String query) {
    DateTimeFormatter formatter = DateTimeFormat.fullDateTime().withLocale(contextService.getLocale());
    User author = message.getAuthor();
    User user = author;
    if (!message.getMessage().getMentionedUsers().isEmpty()) {
        user = message.getMessage().getMentionedUsers().get(0);
    }
    Member member = null;
    if (message.getGuild() != null) {
        member = message.getGuild().getMember(user);
    }

    EmbedBuilder builder = messageService.getBaseEmbed();
    builder.setTitle(messageService.getMessage("discord.command.user.title",
            member != null ? member.getEffectiveName() : user.getName()));
    builder.setImage(user.getEffectiveAvatarUrl());
    builder.setFooter(messageService.getMessage("discord.command.info.identifier", user.getId()), null);

    builder.addField(getName(user, member));
    if (member != null) {
        builder.addField(getOnlineStatus(user, member));
        if (member.getGame() != null) {
            builder.addField(getGame(user, member));
        }
        builder.addField(getJoinedAt(user, member, formatter));
    }
    builder.addField(getCreatedAt(user, member, formatter));
    if (member != null && !user.isBot()) {
        if (rankingService.isEnabled(member.getGuild().getIdLong())) {
            RankingInfo info = rankingService.getRankingInfo(member);
            if (info != null) {
                rankCommand.addFields(builder, info);
            }
        }
        MemberBio memberBio = bioRepository.findByGuildIdAndUserId(member.getGuild().getId(), user.getId());
        String bio = memberBio != null ? memberBio.getBio() : null;
        if (StringUtils.isEmpty(bio) && Objects.equals(author, user)) {
            bio = messageService.getMessage("discord.command.user.bio.none", context.getConfig().getPrefix());
        }
        builder.setDescription(CommonUtils.trimTo(bio, MessageEmbed.TEXT_MAX_LENGTH));
    }
    messageService.sendMessageSilent(message.getChannel()::sendMessage, builder.build());
    return true;
}
 
開發者ID:GoldRenard,項目名稱:JuniperBotJ,代碼行數:46,代碼來源:UserInfoCommand.java


注:本文中的net.dv8tion.jda.core.events.message.MessageReceivedEvent.getGuild方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。