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


Java MessageReceivedEvent類代碼示例

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


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

示例1: onMessageReceived

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入依賴的package包/類
public void onMessageReceived(MessageReceivedEvent event){
    try {
        if (event.getAuthor().isBot()) {
            return;
        }

        //Message Received Diagnostics:
        //System.out.println("NEW MESSAGE LOG: Author: " + event.getAuthor() + "    IDLongText: " + event.getTextChannel().getIdLong() + "   toString: " + event.getTextChannel().toString() + "   Content:" + event.getMessage().getContent());

        /*   <--- For Commands --->   */
        if (event.getMessage().getContent().startsWith(Configuration.getBotPrefix())) {
            IBBot.handleCommand(ParseCommand.parseCommand(event.getMessage().getContent(), event));
        }

        /*   <--- Possible Phrases (As opposed to commands) --->   */
        if (event.getMessage().getContent().toLowerCase().startsWith("link the resources")) {
            IBBot.handlePhrase(ParsePhrase.parsePhrase(event.getMessage().getContent(), event));
        }
        if (event.getMessage().getContent().toLowerCase().startsWith("test phrase")) {
            IBBot.handlePhrase(ParsePhrase.parsePhrase(event.getMessage().getContent(), event));
        }
    }catch(Exception e){
        e.printStackTrace();
    }
}
 
開發者ID:pants1,項目名稱:ib-bot,代碼行數:26,代碼來源:MessageListener.java

示例2: execute

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入依賴的package包/類
@Override
public void execute(MessageReceivedEvent event, String[] args) {
    if (!plugin.getBot().getJDA(event.getGuild()).getGuildById(event.getGuild().getId()).getMember(event.getJDA().getSelfUser()).hasPermission(Permission.MANAGE_ROLES)) {
        event.getChannel().sendMessage("The bot need the \"**Manage Roles**\" permission to be able to set roles to the users.").queue();
        return;
    }
    if (plugin.getBot().getGuildSettings(event.getGuild()).getSetting(WoWLinkPlugin.SETTING_RANKSET_ENABLED) == null) {
        event.getAuthor().openPrivateChannel().queue((c) -> c.sendMessage("Account sync is not enabled in this Discord server.").queue());
        return;
    }

    try {
        String character = plugin.getMainCharacterForUserInGuild(event.getAuthor(), event.getGuild());
        if (character == null) {
            event.getAuthor().openPrivateChannel().queue((c)-> c.sendMessage("You didn't set a main character yet. Please use !setguildcharacter first.").queue());
            return;
        }
        plugin.setDiscordRank(event.getAuthor(),event.getGuild(),plugin.getWoWRank(event.getGuild(), character));
        event.getAuthor().openPrivateChannel().queue((c) -> c.sendMessage("Rank synced!").queue());
    } catch (SQLException e) {
        e.printStackTrace();
        event.getAuthor().openPrivateChannel().queue((c) -> c.sendMessage("An error ocurred. Try again later!").queue());
        plugin.getBot().getStacktraceHandler().sendStacktrace(e, "userid:" + event.getAuthor().getId(), "guildid:" + event.getGuild().getId());
    }

}
 
開發者ID:greatman,項目名稱:legendarybot,代碼行數:27,代碼來源:SyncRankCommand.java

示例3: verify

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入依賴的package包/類
@Override
public String verify(String prefix, String[] args, MessageReceivedEvent event)
{
    String head = prefix + this.name();
    if (args.length != 1)
    {
        return "Incorrect amount of arguments!" +
                "\nUse ``" + head + " <id>``";
    }
    ScheduleEntry entry;
    if (VerifyUtilities.verifyEntryID(args[0]))
    {
        Integer entryId = ParsingUtilities.encodeIDToInt(args[0]);
        entry = Main.getEntryManager().getEntryFromGuild(entryId, event.getGuild().getId());
        if (entry == null)
        {
            return "The requested entry does not exist!";
        }
    }
    else
    {
        return "Argument *" + args[0] + "* is not a valid entry ID!";
    }
    return "";
}
 
開發者ID:notem,項目名稱:Saber-Bot,代碼行數:26,代碼來源:SkipCommand.java

示例4: doInternal

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入依賴的package包/類
@Override
protected boolean doInternal(MessageReceivedEvent message, BotContext context, String content) throws DiscordException {
    RepeatMode mode = messageService.getEnumeration(RepeatMode.class, content);
    if (mode == null) {
        messageManager.onMessage(message.getChannel(), "discord.command.audio.repeat.help",
                Stream.of(RepeatMode.values()).map(messageService::getEnumTitle).collect(Collectors.joining("|")));
        return false;
    }
    PlaybackInstance instance = playerService.getInstance(message.getGuild());
    if (instance.setMode(mode)) {
        messageManager.onMessage(message.getChannel(), "discord.command.audio.repeat", mode.getEmoji());
        if (instance.getCurrent() != null) {
            messageManager.updateMessage(instance.getCurrent());
        }
        return ok(message, "discord.command.audio.repeat", messageService.getEnumTitle(mode));
    }
    messageManager.onMessage(message.getChannel(), "discord.command.audio.notStarted");
    return fail(message);
}
 
開發者ID:GoldRenard,項目名稱:JuniperBotJ,代碼行數:20,代碼來源:RepeatCommand.java

示例5: execute

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入依賴的package包/類
@Override
public void execute(MessageReceivedEvent event, String[] args) {
    if (!event.getMember().getVoiceState().inVoiceChannel()) {
        event.getChannel().sendMessage("You need to be yourself in a voice channel!").queue();
        return;
    }
    String musicChannel = plugin.getBot().getGuildSettings(event.getGuild()).getSetting(MusicPlugin.MUSIC_CHANNEL_SETTING);
    VoiceChannel voiceChannel;
    if (musicChannel != null) {
        List<VoiceChannel> channels = event.getGuild().getVoiceChannelsByName(musicChannel, false);
        if (channels.isEmpty()) {
            event.getChannel().sendMessage("The channel the bot can play in doesn't exist anymore. Please ask an admin to fix it with the ``setmusicchannel`` command.").queue();
            return;
        }
        voiceChannel = channels.get(0);
    } else {
        voiceChannel = event.getMember().getVoiceState().getChannel();
    }

    plugin.getMusicManager().loadAndPlay(event.getTextChannel(), args[0], voiceChannel);
}
 
開發者ID:greatman,項目名稱:legendarybot,代碼行數:22,代碼來源:PlayMusicCommand.java

示例6: parse

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入依賴的package包/類
/**
 * parses a MessageEvent containing a command into it's parts
 * @param e event
 * @return container holding command parts
 */
CommandContainer parse(MessageReceivedEvent e, String prefix)
{
    /// trim off the prefix
    String raw = e.getMessage().getRawContent();
    String trimmed = StringUtils.replaceOnce(raw,prefix, "").trim();

    // split at white spaces (non newlines) or quotation captures
    Matcher matcher = Pattern.compile("[\"\\u201C\\u201D][\\S\\s]*?[\\u201C\\u201D\"]|[^ \"\\u201C\\u201D]+").matcher(trimmed);
    List<String> list = new ArrayList<>();
    while (matcher.find())
    {
        String group = matcher.group();
        if(!group.isEmpty()) list.add(group.replaceAll("[\"\\u201C\\u201D]",""));
    }

    String[] args = list.stream().toArray(String[]::new);

    // separate out first arg
    String invoke = args[0];

    // divide out the remaining args from the first arg
    args = Arrays.copyOfRange(args, 1, args.length);

    return new CommandContainer(prefix, invoke, args, e);
}
 
開發者ID:notem,項目名稱:Saber-Bot,代碼行數:31,代碼來源:CommandParser.java

示例7: execute

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入依賴的package包/類
@Override
public void execute(String[] args, Event event, TaverneBot bot) {
	MessageReceivedEvent mre = (MessageReceivedEvent) event;
	EmbedBuilder builder = new EmbedBuilder();
	builder.setColor(new Color(192, 57, 43));
	builder.setFooter("TaverneBot", null);
	
	if(args.length>=2) {		
		User u = mre.getMessage().getMentionedUsers().get(0);
		if(u.isBot()) return;
		
		builder.setAuthor(u.getName(), null, u.getAvatarUrl()+"?size=256");
		builder.addField("Classement", String.valueOf(bot.getScoreboard().getRank(u)), true);
		builder.addField("Niveaux", String.valueOf(bot.getLevelManager().getLevel(u)), true);
		builder.addField("Exp�riences", String.valueOf(bot.getLevelManager().getXP(u)), true);
		
	} else {
		builder.setAuthor(mre.getAuthor().getName(), null, mre.getAuthor().getAvatarUrl()+"?size=256");
		builder.addField("Classement", String.valueOf(bot.getScoreboard().getRank(mre.getAuthor())), true);
		builder.addField("Niveaux", String.valueOf(bot.getLevelManager().getLevel(mre.getAuthor())), true);
		builder.addField("Exp�riences", String.valueOf(bot.getLevelManager().getXP(mre.getAuthor())), true);
		
	}
		
	((MessageReceivedEvent) event).getTextChannel().sendMessage(builder.build()).queue();
}
 
開發者ID:Nonoland,項目名稱:TaverneBot,代碼行數:27,代碼來源:RankCommand.java

示例8: execute

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入依賴的package包/類
@Override
public void execute(MessageReceivedEvent event, String[] args) {
    plugin.addSetupHandler(event.getGuild(), new SetupHandler(event.getAuthor(), event.getChannel()));
    StringBuilder builder = new StringBuilder();
    builder.append("Thanks for installing Legendarybot! This wizard will help you with the basic configuration of the bot.\n");
    builder.append("It will only take a couple of minutes. If you wish to stop the setup wizard, just say ``cancel``\n");
    builder.append("You don't need to type any command to answer the following questions.\n");
    builder.append("========================================================================\n");
    event.getChannel().sendMessage(builder.toString()).queue();

    builder = new StringBuilder();
    builder.append("A **prefix** is the start of a message that the bot will recognize as a command.\n");
    builder.append("As an example, ``!help`` ``!`` is the prefix and ``help`` is the command.\n");
    builder.append("If you're running more than one Discord bot, you likely don't want two bots answering to the same command.\n\n");
    builder.append("**Default Value**: ``!``\n");

    String prefix = plugin.getBot().getGuildSettings(event.getGuild()).getSetting("PREFIX");
    if (prefix == null) {
        prefix = "!";
    }
    builder.append("**Current Setting**: ``" + prefix + "``\n");
    builder.append("So, what **prefix** would you like to use?");
    event.getChannel().sendMessage(builder.toString()).queue();

}
 
開發者ID:greatman,項目名稱:legendarybot,代碼行數:26,代碼來源:SetupCommand.java

示例9: execute

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入依賴的package包/類
@Override
public void execute(MessageReceivedEvent event, String[] args) {
    Map<String,String> commands = plugin.getServerCommands(event.getGuild());

    StringBuilder builder = new StringBuilder();
    builder.append(plugin.getBot().getTranslateManager().translate(event.getGuild(), "command.listcommand.text") + "\n");
    String prefix = plugin.getBot().getGuildSettings(event.getGuild()).getSetting("PREFIX");
    if (prefix == null) {
        prefix = "!";
    }
    String finalPrefix = prefix;
    commands.forEach((k,v) -> {
        builder.append(finalPrefix);
        builder.append(k);
        builder.append("\n");
    });
    event.getAuthor().openPrivateChannel().complete().sendMessage(builder.toString()).queue();
}
 
開發者ID:greatman,項目名稱:legendarybot,代碼行數:19,代碼來源:ListCommand.java

示例10: run

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入依賴的package包/類
public Result run(String[] args, MessageReceivedEvent e) {
	
	//Iterate over commands
	String m = "";
	for (Command c : Registry.commands) {
		CommandInfo ci = c.getInfo();
		if ("".equals(ci.name)) {continue;}
		
		//Build message
		m += "`" + Config.getPrefix() + ci.name + "` **-** " + c.uses + "\n";
	}
	m = m.substring(0, m.length() - 1);

	String title = "Command usage for " + DateUtils.getUptime();
	MessageEmbed me = MessageUtils.embedMessage(title, null, m, Color.GREEN);
	return new Result(Outcome.SUCCESS, me);
}
 
開發者ID:Tisawesomeness,項目名稱:Minecord,代碼行數:18,代碼來源:UsageCommand.java

示例11: onMessageReceived

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入依賴的package包/類
@Override
public void onMessageReceived(MessageReceivedEvent event)
{
    // Ignore own messages
    if ( event.getAuthor().equals( bot.getSelfUser() ) )
        return;

    // Ignore messages from other channels
    if ( !event.getChannel().getId().contentEquals(channelId) )
        return;

    LOG.trace( "Message from {} with {} attachment(s): {}",
        event.getMember().getEffectiveName(),
        event.getMessage().getAttachments().size(),
        event.getMessage().getContent()
    );
    BRIDGE.onDiscordMessage(event);
}
 
開發者ID:Gamealition,項目名稱:JDiscordIRC,代碼行數:19,代碼來源:DiscordManager.java

示例12: onMessageReceived

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入依賴的package包/類
@Override
public void onMessageReceived(MessageReceivedEvent messageReceivedEvent) {
  input = new Input(messageReceivedEvent);
  output = new Output(input);

  String msg = input.getRawContent().toLowerCase();

  boolean canHandleMessages = !input.getAuthor().isBot();
  boolean isCommandForBot = (msg.startsWith(Main.bot.getPrefix().toLowerCase())) || (msg
      .startsWith(Main.bot.getDefaultPrefix().toLowerCase())) || (msg
      .startsWith(input.getJDA().getSelfUser().getAsMention()))
      || (input.isFromType(ChannelType.PRIVATE)) && canHandleMessages;

  if (isCommandForBot) {
    commandHandler.execute(input, output);
  }
}
 
開發者ID:Svetroid,項目名稱:Hobbes-v1,代碼行數:18,代碼來源:BotListener.java

示例13: relayMessage

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入依賴的package包/類
protected void relayMessage(MessageReceivedEvent event) {
    String msg = event.getMessage().getContent();
    /*
    if (mcb.supportNewFeat() && isSpigot()) {
        TextComponent all = PrefixParser.parseDiscordPrefixesAsTC(configsManager.getChatConfig().getString("Discord_Prefix"), event);
        String format = configsManager.getChatConfig().getString("Message_Format");
        TextComponent content = new TextComponent((format + msg));
        all.addExtra(content);
        getMessenger().sendGlobalMessageToMC(all);
    } else {

    }
     */
    String prefix = PrefixParser.parseDiscordPrefixes(configsManager.getChatConfig().getString("Discord_Prefix"), event);
    String format = configsManager.getChatConfig().getString("Message_Format");
    getMessenger().sendGlobalMessageToMC(ChatColor.translateAlternateColorCodes('&', prefix + " " + (format + msg)).trim());
}
 
開發者ID:CyR1en,項目名稱:Minecordbot,代碼行數:18,代碼來源:TextChannelListener.java

示例14: execute

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入依賴的package包/類
@Override
public void execute(MessageReceivedEvent event, String[] args) {
    if (plugin.getBot().getGuildSettings(event.getGuild()).getGuildName() == null || plugin.getBot().getGuildSettings(event.getGuild()).getRegionName() == null) {
        event.getChannel().sendMessage("You can't run this command. A server administrator need to set GUILD_NAME and WOW_REGION_NAME. Refer to documentation.").queue();
        return;
    }

    List<String> characterList = plugin.getUserCharactersInGuild(event.getAuthor(), event.getGuild());
    if (!characterList.contains(args[0])) {
        event.getAuthor().openPrivateChannel().queue((c) -> c.sendMessage("This character is not in the Guild " + plugin.getBot().getGuildSettings(event.getGuild()).getGuildName() + " or is not found.").queue());
    }

    try {
        plugin.setMainCharacterForGuild(event.getAuthor(), event.getGuild(), args[0]);
        if (plugin.getBot().getGuildSettings(event.getGuild()).getSetting(WoWLinkPlugin.SETTING_RANKSET_ENABLED) != null) {
            plugin.setDiscordRank(event.getAuthor(), event.getGuild(), plugin.getWoWRank(event.getGuild(), args[0]));
        }
        event.getAuthor().openPrivateChannel().queue((c) -> c.sendMessage("Your main character has been set.").queue());
    } catch (SQLException e) {
        e.printStackTrace();
        plugin.getBot().getStacktraceHandler().sendStacktrace(e, "character:" + args[0], "userid:" + event.getAuthor().getId(), "guildid:" + event.getGuild().getId());
    }
}
 
開發者ID:greatman,項目名稱:legendarybot,代碼行數:24,代碼來源:SetMainCharacterCommand.java

示例15: action

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入依賴的package包/類
public void action(String[] args, MessageReceivedEvent messageReceivedEvent){
    try {
        Configuration.changeProperty("ibResourcesPage", args[0]);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
開發者ID:pants1,項目名稱:ib-bot,代碼行數:8,代碼來源:AdminChangeResourcesURL.java


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