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


Java MessageReceivedEvent.getMember方法代码示例

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


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

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

示例2: doInternal

import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //导入方法依赖的package包/类
@Override
protected boolean doInternal(MessageReceivedEvent message, BotContext context, String content) throws DiscordException {
    Member member = message.getMember();
    if (CollectionUtils.isNotEmpty(message.getMessage().getMentionedUsers())) {
        member = message.getGuild().getMember(message.getMessage().getMentionedUsers().get(0));
    }
    RankingInfo info = rankingService.getRankingInfo(member);
    if (info == null) {
        messageService.sendMessageSilent(message.getTextChannel()::sendMessage, messageService.getMessage(
                "discord.command.rank.unavailable"));
        return false;
    }

    if (PermissionUtil.checkPermission(message.getTextChannel(), message.getGuild().getSelfMember(),
            Permission.MESSAGE_EMBED_LINKS)) {
        EmbedBuilder builder = messageService.getBaseEmbed(true);
        addFields(builder, info);
        builder.setAuthor(member.getEffectiveName(), null, member.getUser().getAvatarUrl());
        messageService.sendMessageSilent(message.getTextChannel()::sendMessage, builder.build());
    } else {
        String response;
        if (message.getMember().equals(member)) {
            response = messageService.getMessage("discord.command.rank.info.message.self",
                    member.getAsMention(),
                    info.getRank(),
                    info.getLevel(),
                    info.getRemainingExp(),
                    info.getLevelExp(),
                    info.getTotalExp());
        } else {
            response = messageService.getMessage("discord.command.rank.info.message.member",
                    message.getMember().getAsMention(),
                    member.getAsMention(),
                    info.getRank(),
                    info.getLevel(),
                    info.getRemainingExp(),
                    info.getLevelExp(),
                    info.getTotalExp());
        }
        messageService.sendMessageSilent(message.getTextChannel()::sendMessage, response);
    }
    return true;
}
 
开发者ID:GoldRenard,项目名称:JuniperBotJ,代码行数:44,代码来源:RankCommand.java


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