當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。