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


Java MessageReceivedEvent.getResponseNumber方法代碼示例

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


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


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