本文整理匯總了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();
});
}
}
示例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;
}