当前位置: 首页>>代码示例>>Java>>正文


Java MessageReceivedEvent.getTextChannel方法代码示例

本文整理汇总了Java中net.dv8tion.jda.core.events.message.MessageReceivedEvent.getTextChannel方法的典型用法代码示例。如果您正苦于以下问题:Java MessageReceivedEvent.getTextChannel方法的具体用法?Java MessageReceivedEvent.getTextChannel怎么用?Java MessageReceivedEvent.getTextChannel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.dv8tion.jda.core.events.message.MessageReceivedEvent的用法示例。


在下文中一共展示了MessageReceivedEvent.getTextChannel方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleMessages

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //导入方法依赖的package包/类
private void handleMessages(MessageReceivedEvent event) {
    String channelName = event.getChannel().getName();
    String username = event.getAuthor().getName();
    String message = event.getMessage().getContent();
    String messageId = event.getMessage().getId();
    Channel channel = event.getTextChannel();
    User sender = event.getAuthor();
    Boolean isAdmin = PermissionUtil.checkPermission(channel, event.getMember(), Permission.ADMINISTRATOR);

    com.gmt2001.Console.out.println("[DISCORD] [#" + channelName + "] " + username.toLowerCase() + ": " + message);

    // Be sure that this is commented out before a release back into the master branch!  
    /*
    if (message.equals("!testjoin") && isAdmin) { 
        EventBus.instance().post(new DiscordJoinEvent(event.getMember()));
    }
    */

    if (message.startsWith("!")) {
        commandEvent(sender, channel, message, isAdmin);
    }

    EventBus.instance().postAsync(new DiscordMessageEvent(sender, channel, message, messageId, isAdmin));
}
 
开发者ID:GloriousEggroll,项目名称:quorrabot,代码行数:25,代码来源:DiscordAPI.java

示例2: onMessage

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //导入方法依赖的package包/类
@SubscribeEvent
protected void onMessage(MessageReceivedEvent event)
{
    // TODO: Krobot 2.5.0, handle mentions with space / quotes / etc...

    String[] line = splitWithQuotes(event.getMessage().getContent());

    if (line.length == 0)
    {
        return;
    }

    for (Command command : commands)
    {
        if (command.getLabel().equalsIgnoreCase(line[0]))
        {
            if (typing)
            {
                event.getChannel().sendTyping().queue();
            }

            CommandContext context = new CommandContext(event.getAuthor(), event.getMessage(), event.getTextChannel());
            List<String> args = Arrays.asList(ArrayUtils.subarray(line, 1, line.length));

            try
            {
                command.call(context, args);
            }
            catch (Throwable t)
            {
                exHandler.handle(t, command, args, context);
            }

            return;
        }
    }
}
 
开发者ID:krobot-framework,项目名称:krobot,代码行数:38,代码来源:CommandManager.java

示例3: exampleTimeout

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //导入方法依赖的package包/类
public exampleTimeout(MessageReceivedEvent event) {
	channel = event.getTextChannel();
}
 
开发者ID:JessWalters,项目名称:Vinny-Redux,代码行数:4,代码来源:Bot.java

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


注:本文中的net.dv8tion.jda.core.events.message.MessageReceivedEvent.getTextChannel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。