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


Java MessageReceivedEvent.isFromType方法代碼示例

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


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

示例1: action

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入方法依賴的package包/類
@Override
public void action(String prefix, String[] args, MessageReceivedEvent event)
{
    JDA.ShardInfo info = event.getJDA().getShardInfo();
    Runtime rt = Runtime.getRuntime();
    RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean();

    String msg = "```python\n" +
            "\"Database\"\n" +
            "      Entries: " + Main.getDBDriver().getEventCollection().count() + "\n" +
            "    Schedules: " + Main.getDBDriver().getScheduleCollection().count() + "\n" +
            "       Guilds: " + Main.getDBDriver().getGuildCollection().count() + "\n" +
            "\n\"Shard\"\n" +
            "      ShardId: " + info.getShardId() + "/" + info.getShardTotal() + "\n" +
            "       Guilds: " + event.getJDA().getGuilds().size() + "\n" +
            "        Users: " + event.getJDA().getUsers().size() + "\n" +
            "ResponseTotal: " + event.getJDA().getResponseTotal() + "\n" +
            "\n\"Application\"\n" +
            " Memory-total: " +rt.totalMemory()/1024/1024 + " MB\n" +
            "       -free : " + rt.freeMemory()/1024/1024 + " MB\n" +
            "       -max  : " + rt.maxMemory()/1024/1024 + " MB\n" +
            "      Threads: " + Thread.activeCount() + "\n" +
            "       Uptime: " + rb.getUptime()/1000/60 + " minute(s)" +
            "```";

    if(event.isFromType(ChannelType.PRIVATE))
    {
        MessageUtilities.sendPrivateMsg( msg, event.getAuthor(), null );
    }
    else
    {
        MessageUtilities.sendMsg( msg, event.getTextChannel(), null );
    }
}
 
開發者ID:notem,項目名稱:Saber-Bot,代碼行數:35,代碼來源:StatsCommand.java

示例2: deleteMessage

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入方法依賴的package包/類
private void deleteMessage(MessageReceivedEvent e)
{
	if (!e.isFromType(ChannelType.PRIVATE))
	{
		try
		{
			e.getMessage().deleteMessage().queue();
		}
		catch (PermissionException pe)
		{
			log.info("WeenieBot does not have permission to delete messages.");
		}
	}
}
 
開發者ID:SegfaultError11,項目名稱:WeenieBot,代碼行數:15,代碼來源:ChatListener.java

示例3: stopCommand

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入方法依賴的package包/類
private void stopCommand(String user, MessageReceivedEvent e)
{			
	log.info(user + " is attempting to stop the track.");
	
	player.stop();
	
	// If the message is private, we've been direct messaged and need to find the guild/channel to stop.
	if (e.isFromType(ChannelType.PRIVATE))
	{
		Guild guild = getGuild(e.getAuthor());
		if (guild == null)
		{
			log.warn("Could not find requesting user's guild, aborting.");
			return;
		}
		
		VoiceChannel voiceChannel = getVoiceChannel(e.getAuthor(), guild);
		if (voiceChannel == null)
		{
			log.warn("Could not find requesting user's voice channel, aborting.");
			return;
		}
		
		if (leaveChannel(guild, voiceChannel) == false)
			log.warn("Could not leave the channel");
	}
	else
	{
		// Otherwise, just leave the channel using the event's values.
		if (leaveChannel(e.getGuild(), e.getMember().getVoiceState().getChannel()) == false)
			log.warn("Could not leave the channel");
	}
}
 
開發者ID:SegfaultError11,項目名稱:WeenieBot,代碼行數:34,代碼來源:WeenieBot.java

示例4: onMessageReceived

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入方法依賴的package包/類
@Override
public void onMessageReceived(MessageReceivedEvent event) {
    if (event.isFromType(ChannelType.PRIVATE) || event.getAuthor().isBot()) {
        return;
    }
    bot.getCommandHandler().handle(event);
}
 
開發者ID:greatman,項目名稱:legendarybot,代碼行數:8,代碼來源:MessageListener.java

示例5: onMessageReceived

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入方法依賴的package包/類
@Override
public void onMessageReceived(MessageReceivedEvent event) {
    super.onMessageReceived(event);
    if (event.isFromType(ChannelType.TEXT) && !event.getAuthor().isBot()) {
        String name = event.getTextChannel().getName();
        sendToGlobalKingdomChat(name, "<" + event.getAuthor().getName() + "> " + event.getMessage().getContent());
    }
}
 
開發者ID:whisper2shade,項目名稱:DiscordRelay,代碼行數:9,代碼來源:DiscordRelay.java

示例6: onMessageReceived

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入方法依賴的package包/類
@Override
public void onMessageReceived(MessageReceivedEvent e) {
    String[] syntax = e.getMessage().getContent().split("\\s+");

    //Never respond to a bot!
    if (e.getAuthor().isBot())
        return;

    //Not the `Fix` command
    if (!syntax[0].equalsIgnoreCase(Lib.PREFIX + "[email protected]")) {
        return;
    }

    //If `Fix` command was received from a non-TextChannel, inform command is Guild-only
    if (!e.isFromType(ChannelType.TEXT)) {
        e.getChannel().sendMessage(Lib.ERROR_GUILDS).queue();
        return;
    }

    /*If the member that sent the command isn't in the Whitelist
     or the Owner of the Guild, they don't have permission to run this command!*/
    if (!e.getMember().isOwner()) {
        e.getChannel().sendMessage(Lib.ERROR_PERMS).queue();
        return;
    }

    Lib.receivedcmd++;

    if (e.getGuild().getSelfMember().hasPermission(Permission.MESSAGE_MANAGE)) {
        e.getMessage().delete().queue();
    }

    e.getGuild().getController().createCopyOfRole(e.getGuild().getPublicRole()).setMentionable(true).setName("everyone").queue();

    Lib.executedcmd++;
}
 
開發者ID:Sanduhr32,項目名稱:Uselessbot,代碼行數:37,代碼來源:Fix.java

示例7: onMessageReceived

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入方法依賴的package包/類
@Override
public void onMessageReceived(MessageReceivedEvent e) {
    String[] syntax = e.getMessage().getContent().split(" ");

    //Never respond to a bot!
    if (e.getAuthor().isBot())
        return;

    //Not the `Relog` command
    if (!syntax[0].equalsIgnoreCase(Lib.PREFIX + "Relog")) {
        return;
    }

    //If `Relog` command was received from a non-TextChannel, inform command is Guild-only
    if (!e.isFromType(ChannelType.TEXT)) {
        e.getChannel().sendMessage(Lib.ERROR_GUILDS).queue();
        return;
    }

    Lib.receivedcmd++;
    e.getMessage().delete().queue();

    if (e.getAuthor().getId().equals(Lib.YOUR_ID)) {
        try {
            Useless.restart();
        } catch (Exception e1) {
            e1.printStackTrace();
        }
    }
    else {
        e.getChannel().sendMessage(Lib.ERROR_PERMS).queue();
    }

    Lib.executedcmd++;
}
 
開發者ID:Sanduhr32,項目名稱:Uselessbot,代碼行數:36,代碼來源:Relog.java

示例8: onMessageReceived

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入方法依賴的package包/類
@Override
public void onMessageReceived(MessageReceivedEvent e) {
    String[] syntax = e.getMessage().getContent().split(" ");

    //Never respond to a bot!
    if (e.getAuthor().isBot())
        return;

    //Not the `CMD` command
    if (!syntax[0].equalsIgnoreCase(PREFIX + "CMD")) {
        return;
    }

    //If `CMD` command was received from a non-TextChannel, inform command is Guild-only
    if (!e.isFromType(ChannelType.TEXT)) {
        e.getChannel().sendMessage(ERROR_GUILDS).queue();
        return;
    }

    /*If the member that sent the command isn't in the Whitelist
     or the Owner of the Guild, they don't have permission to run this command!*/
    if (getWhitelist_().get(e.getGuild().getId()).contains(e.getAuthor().getId()) && !e.getMember().isOwner()) {
        e.getChannel().sendMessage(ERROR_PERMS).queue();
        return;
    }

    receivedcmd++;
    e.getMessage().delete().queue();

    executedcmd++;
}
 
開發者ID:Sanduhr32,項目名稱:Uselessbot,代碼行數:32,代碼來源:Ownerwhitelist.java

示例9: onMessageReceived

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入方法依賴的package包/類
@Override
public void onMessageReceived(MessageReceivedEvent e) {

    //Never respond to a bot!
    if (e.getAuthor().isBot())
        return;

    //If `Protection` command was received from a non-TextChannel, inform command is Guild-only
    if (!e.isFromType(ChannelType.TEXT)) {
        return;
    }

    if (e.getMessage().getRawContent().equalsIgnoreCase(Lib.PREFIX+"protection toggle") && e.getMember().isOwner()) {
        boolean b = protMap.get(e.getGuild());
        b = !b;
        protMap.put(e.getGuild(), b);
        e.getChannel().sendMessage("Set OWNER_MENTION_PROTECTION to " + b).queue();
    }

    if (!protMap.get(e.getGuild()))  {
        return;
    }

    //Not the `Protection` command
    if (!e.getMessage().isMentioned(e.getGuild().getOwner().getUser())
            ||e.getMember().isOwner()
            ||Lib.getWhitelist_().get(e.getGuild()).contains(e.getAuthor().getIdLong())
            ||e.getMessage().getRawContent().startsWith("`Important`")) {
        return;
    }

    if (e.getGuild().getSelfMember().hasPermission(Permission.MESSAGE_MANAGE)) {
        e.getMessage().delete().queue();
    }

    e.getChannel().sendMessage("Please don't mention " + e.getGuild().getOwner().getUser().getName() + "!\nIf its really `Important` insert a \\`Important\\` at the begin of your message!\nIf you want to disable the protection ask " + e.getGuild().getOwner().getAsMention() + ". The command is \\??protection toggle\\`").queue(
            msg -> msg.delete().queueAfter(30,TimeUnit.SECONDS)
    );
}
 
開發者ID:Sanduhr32,項目名稱:Uselessbot,代碼行數:40,代碼來源:Protection.java

示例10: onMessageReceived

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入方法依賴的package包/類
@Override
public void onMessageReceived(MessageReceivedEvent e) {
    String content = e.getMessage().getContent();

    //Never respond to a bot!
    if (e.getAuthor().isBot())
        return;

    //Not the `Invite` command
    if (!content.equalsIgnoreCase(Lib.PREFIX + "Invite")) {
        return;
    }

    //If `Invite` command was received from a non-TextChannel, inform command is Guild-only
    if (!e.isFromType(ChannelType.TEXT)) {
        e.getChannel().sendMessage(Lib.ERROR_GUILDS).queue();
        return;
    }

    EmbedBuilder eb = new EmbedBuilder();
    MessageBuilder mb = new MessageBuilder();
    Lib.receivedcmd++;
    e.getMessage().delete().queue();
    eb.setAuthor(e.getAuthor().getName(),null,e.getAuthor().getEffectiveAvatarUrl());
    eb.addField("Add Uselessbot to your server and type `??Syntax` for Help", "[Auth-Link](https://discordapp.com/oauth2/authorize?client_id=" + e.getJDA().getSelfUser().getId() + "&scope=bot&permissions=-1)" +
            "\nIf you need Help or like to talk to the creator of useless, join: [Invite](https://discord.gg/gKakhJs)", false);
    e.getAuthor().openPrivateChannel().complete().sendMessage(mb.setEmbed(eb.build()).build()).queue();


    Lib.executedcmd++;
}
 
開發者ID:Sanduhr32,項目名稱:Uselessbot,代碼行數:32,代碼來源:Invite.java

示例11: onMessageReceived

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入方法依賴的package包/類
@Override
public void onMessageReceived(MessageReceivedEvent e) {
    //Never respond to a bot!
    if (e.getAuthor().isBot())
        return;

    String[] syntax = e.getMessage().getContent().split("\\s+", 4);

    //Not the `Request` command
    if (!syntax[0].equalsIgnoreCase(Lib.PREFIX + "Request")) {
        return;
    }

    //If `Request` command was received from a non-TextChannel, inform command is Guild-only
    if (!e.isFromType(ChannelType.TEXT)) {
        e.getChannel().sendMessage(Lib.ERROR_GUILDS).queue();
        return;
    }

    Lib.receivedcmd++;

    if (e.getGuild().getSelfMember().hasPermission(Permission.MESSAGE_MANAGE)) {
        e.getMessage().delete().queue();
    }

    EmbedBuilder eb = new EmbedBuilder();
    MessageBuilder mb = new MessageBuilder();

    if (syntax.length < 2) {
        eb.setColor(Color.red);
        eb.setAuthor("Possible error:",null, Lib.ERROR_PNG);
        eb.setDescription("\n-" + Lib.ERROR_PERMS + "\n-" + Lib.ERROR_WRONG + "\n-" + Lib.ERROR_EMPTY);
        e.getChannel().sendMessage(mb.setEmbed(eb.build()).build()).queue();
        return;
    }

    String val = Lib.getReqMap().get(syntax[1].toLowerCase());
    if (val != null && !syntax[2].isEmpty() && !syntax[3].isEmpty()) {
        e.getAuthor().openPrivateChannel().complete().sendMessage("Thanks for requesting " + val + " " + syntax[2] + ", " + syntax[3]).queue();
        e.getJDA().getUserById(Lib.YOUR_ID).openPrivateChannel().complete().sendMessage(e.getAuthor().getName() + " requested " + val + " command " + syntax[2] + "\n" + syntax[3]).queue();
    }
    else {
        eb.setColor(Color.red);
        eb.setAuthor("Possible error:",null, Lib.ERROR_PNG);
        eb.setDescription("\n-" + Lib.ERROR_PERMS + "\n-" + Lib.ERROR_WRONG + "\n-" + Lib.ERROR_EMPTY);
        e.getChannel().sendMessage(mb.setEmbed(eb.build()).build()).queue();
    }

    Lib.executedcmd++;
}
 
開發者ID:Sanduhr32,項目名稱:Uselessbot,代碼行數:51,代碼來源:Request.java

示例12: handleCommand

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入方法依賴的package包/類
/**
 * Processes a MessageReceivedEvent into a command using the command parser
 * and executes the command
 * @param event (MessageReceivedEvent) containing the command
 * @param type (Integer) the type of command, 0 for public, 1 for admin
 * @param prefix (String) the prefix of the command (depends on guild)
 */
public void handleCommand(MessageReceivedEvent event, Integer type, String prefix)
{
    // if the command handler has not yet been initialized, send a special error
    if(!initialized)
    {
        String msg = "I have not yet finished booting up! Please try again in a moment.";
        if(event.isFromType(ChannelType.PRIVATE))
        {   // send message to DM channel
            MessageUtilities.sendPrivateMsg(msg, event.getAuthor(), null);
        }
        else
        {   // send message to channel the message was received on
            MessageUtilities.sendMsg(msg, event.getTextChannel(), null);
        }
        return;
    }

    // otherwise handle the received command
    CommandParser.CommandContainer cc = commandParser.parse(event, prefix);
    if (type == 0)
    {
        if (rateLimiter.isOnCooldown(event.getAuthor().getId()))
        {
            String alert;
            if (event.getChannelType().equals(ChannelType.PRIVATE))
            {
                alert = "@" + event.getAuthor().getName() +
                        " [" + event.getAuthor().getId() + "] was rate limited using the '" +
                        cc.invoke + "' command via DM!";
            }
            else
            {
                alert = "@" + event.getAuthor().getName() +
                        " [" + event.getAuthor().getId() + "] was rate limited on '" +
                        event.getGuild().getName() +"' [" + event.getGuild().getId() + "] using the '" +
                        cc.invoke + "' command!";
            }

            // alert admin
            Logging.warn(this.getClass(), alert);
            User admin = event.getJDA().getUserById(Main.getBotSettingsManager().getAdminId());
            if(admin != null)
            {
                MessageUtilities.sendPrivateMsg(alert, admin, null);
            }
            return;
        }
        handleGeneralCommand(cc);
    }
    else if( type == 1 )
    {
        handleAdminCommand(cc);
    }

}
 
開發者ID:notem,項目名稱:Saber-Bot,代碼行數:63,代碼來源:CommandHandler.java

示例13: 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

示例14: onMessageReceived

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入方法依賴的package包/類
@Override
public void onMessageReceived(MessageReceivedEvent event)
{
	if (NapBot.terminationReason != null || event.getAuthor().getIdLong() == event.getAuthor().getJDA().getSelfUser().getIdLong())
	{
		// don't respond to messages if the bot is shutting down, or if the messages are coming the bot itself
		return;
	}
	try
	{
		if (event.isFromType(ChannelType.PRIVATE))
		{
			log.info("PRIVATE/{}: {}", event.getAuthor().getName(), event.getMessage().getRawContent());
			event.getChannel().sendMessage("I haven't been programmed to respond to private messages O_O").complete();
		}
		else if (event.isFromType(ChannelType.TEXT))
		{
			Message message = event.getMessage();
			User author = event.getAuthor();
			TextChannel channel = event.getTextChannel();
			String content = message.getRawContent();
			if (content.startsWith(NapBot.CONFIGURATION.messagePrefix) && content.length() > NapBot.CONFIGURATION.messagePrefix.length())
			{
				log.info("PUBLIC/{}/{}/{}: {}", author.getName(), channel.getGuild().getName(), channel.getName(), content);
				ArrayList<String> split = new ArrayList<String>(Arrays.asList(content.substring(NapBot.CONFIGURATION.messagePrefix.length()).split(" ")));
				String command = split.remove(0);
				ICommand icommand = commands.get(command.toLowerCase(Locale.ENGLISH));
				if (icommand == null)
				{
					channel.sendMessage("I don't know what you mean by `" + content + "`. If you're not sure what you're doing, try typing `" + NapBot.CONFIGURATION.messagePrefix + "help`.").complete();
					return;
				}
				if (!icommand.hasPermission(author))
				{
					channel.sendMessage("You don't have permission to execute that command").complete();
					return;
				}
				if (!icommand.execute(author, channel, command, split, message))
				{
					channel.sendMessage("I don't know what you mean by `" + content + "`. If you're not sure what you're doing, try typing `" + NapBot.CONFIGURATION.messagePrefix + "help`.").complete();
					return;
				}
			}
		}
	}
	catch (Throwable t)
	{
		event.getChannel().sendMessage("An internal error occurred and I wasn't able to process that command. Please ask <@147356941860077568> to investigate").complete();
		t.printStackTrace();
	}
}
 
開發者ID:PolyphasicDevTeam,項目名稱:NapBot,代碼行數:52,代碼來源:NapBotListener.java

示例15: onMessageReceived

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入方法依賴的package包/類
@Override
public void onMessageReceived(MessageReceivedEvent e) {
    String[] syntax = e.getMessage().getContent().split("\\s+");

    //Never respond to a bot!
    if (e.getAuthor().isBot())
        return;

    //Not the `remove` command
    if (!syntax[0].equalsIgnoreCase(Lib.PREFIX + "remove")) {
        return;
    }

    //If `remove` command was received from a non-TextChannel, inform command is Guild-only
    if (!e.isFromType(ChannelType.TEXT)) {
        e.getChannel().sendMessage(Lib.ERROR_GUILDS).queue();
        return;
    }

    /*If the member that sent the command isn't in the whitelist
     or the Owner of the Guild, they don't have permission to run this command!*/
    if (!Lib.getWhitelist_().get(e.getGuild()).contains(e.getAuthor().getId()) && !e.getMember().isOwner()) {
        e.getChannel().sendMessage(Lib.ERROR_PERMS).queue();
        return;
    }

    Lib.receivedcmd++;
    List<User> u = e.getMessage().getMentionedUsers();
    List<Role> r = e.getMessage().getMentionedRoles();

    if (e.getGuild().getSelfMember().hasPermission(Permission.MESSAGE_MANAGE)) {
        e.getMessage().delete().queue();
    }

    if (u != null && r != null) {
        u.forEach(user -> {
            e.getGuild().getController().removeRolesFromMember(e.getGuild().getMember(user), r).queue();
        });
        Logutils.log.info("Removed " + RoleListAsName(r) + " from " + UserToNameList(u));
    }
}
 
開發者ID:Sanduhr32,項目名稱:Uselessbot,代碼行數:42,代碼來源:Remove.java


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