当前位置: 首页>>代码示例>>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;未经允许,请勿转载。