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


Java MessageReceivedEvent.getChannel方法代碼示例

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


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

示例1: onMessageReceived

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入方法依賴的package包/類
@Override
public void onMessageReceived(MessageReceivedEvent event) {
    JDA jda = event.getJDA();
    long responseNumber = event.getResponseNumber();

    User author = event.getAuthor();                    //The user that sent the message
    Message message = event.getMessage();               //The message that was received
    MessageChannel channel = event.getChannel();        //The channel the message was sent in

    TransparentDiscord.receiveMessage(message, channel);
}
 
開發者ID:MCPlummet,項目名稱:TransparentDiscord,代碼行數:12,代碼來源:MessageListener.java

示例2: onMessageReceived

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入方法依賴的package包/類
@Override
public void onMessageReceived(MessageReceivedEvent event)
{
    JDA jda = event.getJDA();
    //Amount of Discord events that JDA has received since the last reconnect
    long responsNo = event.getResponseNumber();

    //Event specific information

    User user = event.getAuthor();
    Message message = event.getMessage();
    MessageChannel channel = event.getChannel();    //Could be a TextChannel, PrivateChannel or Group

    String messageText = message.getContent();
    boolean isBot = user.isBot();

    //FYI in the API, Guilds are Servers
    ChannelType type = event.getChannelType();
    String guildName;
    String channelName = channel.getName();
    String userName = user.getName();

    if(type.isGuild())
    {
        guildName = event.getGuild().getName();
        Member member = event.getMember();

        //If this is a Webhook message then there is no Member associated with the User, so we use User for the name
        //If not a Webhook message, we'll use the Member's nickname if they have one. Otherwise we'll use their username
        userName = message.isWebhookMessage() ? user.getName() : member.getEffectiveName();
    }
    else
    {
        guildName = type.toString();
    }

    if(isBot) userName = "BOT:" + userName;

    Util.info(getClass(),"(" + guildName + ")[" + channelName + "]<" + userName + ">: " + messageText);


    if(messageText.equals("hello"))
        channel.sendMessage("Hello " + user.getAsMention() + "!").queue();
    else if(messageText.equals("roll"))
    {
        int roll = new Random().nextInt(6) + 1;
        channel.sendMessage("Your roll: " + roll).queue(message1 ->
        {
            if(roll < 3)
                channel.sendMessage("Ohh that was a bit of a low roll...").queue();
        });
    }
}
 
開發者ID:thebrightspark,項目名稱:MDC-Discord-Bot,代碼行數:54,代碼來源:MessageReceivedListener.java

示例3: onMessageReceived

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入方法依賴的package包/類
@Override
public void onMessageReceived(MessageReceivedEvent event) {
	String message = event.getMessage().getContentDisplay();
	MessageChannel channel = event.getChannel();
	User author = event.getAuthor();

	if ( (channel == controlChannel || channel.getType() == ChannelType.PRIVATE) && message.startsWith(Config.get(Config.COMMAND_PREFIX)) && (!author.getId().equals(api.getSelfUser().getId())) ) {

		Log.debug("Got command from {}: {}", author.getName(), message);

		String[] cmdarg = message.substring(Config.get(Config.COMMAND_PREFIX).length()).split(" ", 2);
		String cmd = cmdarg[0];
		String arg;
		try {
			arg = cmdarg[1];
		} catch (IndexOutOfBoundsException e) {
			arg = null;
		}

		boolean commandFound = false;

		for(Command command : Command.commands) {
			if (command.compare(cmd)) {
				commandFound = true;

				if(command.hasPermission(author)) {
					command.execute(arg, author, channel, guild);
				} else {
					channel.sendMessage(author.getAsMention() + " ``You are not allowed to use this command.``").queue();
				}

				break;
			}
		}

		if(commandFound) {
			return;
		}

		channel.sendMessage(author.getAsMention() + " ``Unknown command``").queue();

	}
}
 
開發者ID:Bleuzen,項目名稱:Blizcord,代碼行數:44,代碼來源:Bot.java

示例4: onMessageReceived

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入方法依賴的package包/類
@Override
public void onMessageReceived(MessageReceivedEvent event) {
    CoreConfig config = this.phononPlugin.getConfigAdapter(CoreModule.ID, CoreConfigAdapter.class).get().getNodeOrDefault();

    if (event.getMessage().getRawContent().startsWith(config.getPrefix()) && !event.getMessage().getAuthor().isBot()) {
        DiscordCommandSource source = new DiscordCommandSource(event.getAuthor(), event.getChannel());

        int end = event.getMessage().getRawContent().indexOf(" ");
        String commandName;
        String arguments;
        if (end == -1) {
            commandName = event.getMessage().getRawContent().substring(1);
            arguments = "";
        } else {
            commandName = event.getMessage().getRawContent().substring(1, end);
            arguments = event.getMessage().getRawContent().substring(end + 1);
        }


        if (aliases.containsKey(commandName)) {
            IDiscordCommand command = aliases.get(commandName);
            CommandElement args= null;
            try {
                CommandArgs commandArgs = new CommandArgs(arguments,
                        InputTokenizer.quotedStrings(false).tokenize(arguments, true));
                CommandContext context = new CommandContext();
                args = GenericArguments.seq(command.getArgs());
                args.parse(source, commandArgs, context);
                if (commandArgs.hasNext()) {
                    commandArgs.next();
                    throw commandArgs.createError(t("Invalid arguments!"));
                }
                command.execute(event.getAuthor(), context, event.getChannel());
            } catch (ArgumentParseException e) {
                String message = "Invalid Arguments";
                if (e.getMessage() != null) {
                    message = e.getMessage();
                }

                if (args == null) {
                    event.getChannel().sendMessage(message).queue();
                } else {
                    event.getChannel().sendMessage(message + System.lineSeparator() +
                            config.getPrefix() + commandName + args.getUsage(source).toPlain()).queue();
                }
            }

            if (!(event.getChannel() instanceof PrivateChannel)) {
                event.getMessage().delete().queue();
            }
        }
    }
}
 
開發者ID:NucleusPowered,項目名稱:Phonon,代碼行數:54,代碼來源:CommandListener.java


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