本文整理汇总了Java中net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent.getMember方法的典型用法代码示例。如果您正苦于以下问题:Java GuildMessageReceivedEvent.getMember方法的具体用法?Java GuildMessageReceivedEvent.getMember怎么用?Java GuildMessageReceivedEvent.getMember使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent
的用法示例。
在下文中一共展示了GuildMessageReceivedEvent.getMember方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; //导入方法依赖的package包/类
@Override
public boolean run(DiscordBot bot, GuildMessageReceivedEvent event, String args) {
Scanner messageIterator = new Scanner(args);
Member member = event.getMember();
Message message = event.getMessage();
TextChannel channel = event.getChannel();
Guild guild = event.getGuild();
Member selfMember = guild.getSelfMember();
if (!member.hasPermission(Permission.MESSAGE_MANAGE)) {
DiscordUtils.failMessage(bot, message, "You don't have enough permissions to execute this command! Required permission: Manage Messages");
return false;
}
if (!selfMember.hasPermission(Permission.MESSAGE_MANAGE)) {
DiscordUtils.failMessage(bot, message, "I don't have enough permissions to do that!");
return false;
}
if (!messageIterator.hasNextInt()) {
DiscordUtils.failReact(bot, message);
return true;
}
int messageCount = messageIterator.nextInt();
if (messageCount < 1) {
DiscordUtils.failMessage(bot, message, "You can't delete zero or negative messages.");
return false;
} else if (messageCount > 100) {
DiscordUtils.failMessage(bot, message, "You can't delete more than 100 messages at once.");
return false;
}
String targetArgument;
User targetUser = null;
if (!messageIterator.hasNext()) {
targetArgument = "";
} else if (messageIterator.hasNext(DiscordUtils.USER_MENTION_PATTERN)) {
targetUser = message.getMentionedUsers().get(0);
targetArgument = "user";
} else {
targetArgument = messageIterator.next();
}
List<Message> messages;
switch (targetArgument) {
case "":
messages = fetchMessages(channel, messageCount, true, false, false, null);
break;
case "bot":
messages = fetchMessages(channel, messageCount, false, true, false, null);
break;
case "user":
if (targetUser != null) {
messages = fetchMessages(channel, messageCount, true, false, true, targetUser);
break;
}
default:
DiscordUtils.failMessage(bot, message, "Invalid target, please try mentioning a user or writing `bot`.");
return false;
}
Pair<List<Message>, List<Message>> seperatedMessages = seperateMessages(messages);
bulkDelete(seperatedMessages, channel);
DiscordUtils.successReact(bot, message);
return false;
}
示例2: createPoll
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; //导入方法依赖的package包/类
private void createPoll(String[] args, GuildMessageReceivedEvent event){
Message message = event.getMessage();
User author = event.getAuthor();
if(permissionHandler.check(2,event)){
if(permissionHandler.check(2,event)){
embedSender.sendEmbed("Sorry, " + author.getAsMention() + " but you don't have the permission to perform that command!", channel, Color.red);
return;
}
return;
}
String argsSTRG = String.join(" ", new ArrayList<>(Arrays.asList(args).subList(1, args.length)));
List<String> content = Arrays.asList(argsSTRG.split("\\|"));
String heading = content.get(0);
List<String> answers = new ArrayList<>(content.subList(1, content.size()));
Message pollmessage = channel.sendMessage(new EmbedBuilder().setDescription("Creating poll...").setColor(Color.cyan).build()).complete();
String pollmsg = pollmessage.getId();
Poll poll = new Poll(event.getMember(), heading, answers, pollmsg);
polls.put(event.getGuild(), poll);
List<String> emotis = new ArrayList<>(Arrays.asList(EMOTI));
answers.forEach(a -> {
toAddEmojis.add(emotis.get(0));
emotis.remove(0);
});
new Timer().schedule(new TimerTask() {
@Override
public void run() {
pollmessage.editMessage(getParsedPoll(poll, event.getGuild()).build()).queue();
toAddEmojis.forEach((String s) -> pollmessage.addReaction(s).queue());
}
}, 1500);
}
示例3: editTag
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; //导入方法依赖的package包/类
private void editTag(DiscordBot bot, GuildMessageReceivedEvent event, Scanner messageIterator) {
DSLContext database = bot.getDatabase();
Guild guild = event.getGuild();
Message message = event.getMessage();
Member member = event.getMember();
if (!member.hasPermission(Permission.ADMINISTRATOR)) {
DiscordUtils.failMessage(bot, message, "You don't have enough permissions to use this command!");
return;
}
if (!messageIterator.hasNext()) {
DiscordUtils.failMessage(bot, message, "Please provide a tag name and a response to edit tags!");
return;
}
String tagName = messageIterator.next();
String response = TextUtils.seekScannerToEnd(messageIterator);
if (response.equals("")) {
DiscordUtils.failMessage(bot, message, "Empty responses aren't allowed!");
return;
}
TaglistRecord record = database.selectFrom(Tables.TAGLIST)
.where(Tables.TAGLIST.GUILDID.eq(guild.getId()))
.and(Tables.TAGLIST.NAME.eq(tagName))
.fetchOne();
if (record == null) {
DiscordUtils.failMessage(bot, message, "Tag `" + tagName + "` does not exist!");
return;
}
record.setResponse(response);
record.update();
DiscordUtils.successReact(bot, message);
}
示例4: deleteTag
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; //导入方法依赖的package包/类
private void deleteTag(DiscordBot bot, GuildMessageReceivedEvent event, Scanner messageIterator) {
DSLContext database = bot.getDatabase();
Guild guild = event.getGuild();
Message message = event.getMessage();
Member member = event.getMember();
if (!member.hasPermission(Permission.ADMINISTRATOR)) {
DiscordUtils.failMessage(bot, message, "You don't have enough permissions to use this command!");
return;
}
if (!messageIterator.hasNext()) {
DiscordUtils.failMessage(bot, message, "Please provide a tag name and a response to delete tags!");
return;
}
String tagName = messageIterator.next();
TaglistRecord record = database.selectFrom(Tables.TAGLIST)
.where(Tables.TAGLIST.GUILDID.eq(guild.getId()))
.and(Tables.TAGLIST.NAME.eq(tagName))
.fetchOne();
if (record == null) {
DiscordUtils.failMessage(bot, message, "Tag `" + tagName + "` does not exist!");
return;
}
record.delete();
DiscordUtils.successReact(bot, message);
}
示例5: SafeGuildMessageReceivedEvent
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; //导入方法依赖的package包/类
public SafeGuildMessageReceivedEvent(GuildMessageReceivedEvent event, int maxMessages) {
this.event = event;
this.channel = new SafeChannel(event.getChannel(), maxMessages);
this.author = new SafeUser(event.getAuthor());
this.member = new SafeMember(event.getMember());
this.guild = new SafeGuild(event.getGuild(), channel);
this.message = new SafeMessage(event.getMessage());
}
示例6: run
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; //导入方法依赖的package包/类
@Override
public boolean run(DiscordBot bot, GuildMessageReceivedEvent event, String args) {
Member member = event.getMember();
Message message = event.getMessage();
Guild guild = event.getGuild();
GuildController controller = guild.getController();
List<User> mentions = message.getMentionedUsers();
DSLContext database = bot.getDatabase();
if (!member.hasPermission(Permission.MANAGE_ROLES)) {
DiscordUtils.failMessage(bot, message, "You don't have enough permissions to execute this command! Required permission: Manage Roles");
return false;
}
if (!guild.getSelfMember().hasPermission(Permission.MANAGE_ROLES)) {
DiscordUtils.failMessage(bot, message, "I don't have enough permissions do this action!");
return false;
}
// If no arguments are given or there are no mentions or first word isn't a user mention, display syntax text
if (args.equals("") || mentions.size() == 0) {
return true;
}
Role muteRole = guild.getRolesByName("Muted", false).get(0);
if (muteRole == null) {
DiscordUtils.failMessage(bot, message, "Could not find a role called Muted, please create one yourself or mute a user to set it up automatically.");
return false;
}
for (User unmuteUser: mentions) {
Member unmuteMember = guild.getMember(unmuteUser);
controller.removeSingleRoleFromMember(unmuteMember, muteRole).queue();
Result<MutelistRecord> records = database.selectFrom(Tables.MUTELIST)
.where(Tables.MUTELIST.USERID.eq(unmuteUser.getId()))
.and(Tables.MUTELIST.GUILDID.eq(guild.getId()))
.fetch();
if (records.isEmpty()) {
continue;
}
for (MutelistRecord record: records) {
record.setUnmuted(true);
record.update();
}
}
DiscordUtils.successReact(bot, message);
return false;
}
示例7: run
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; //导入方法依赖的package包/类
@Override
public boolean run(DiscordBot bot, GuildMessageReceivedEvent event, String args) {
Scanner messageIterator = new Scanner(args);
DSLContext database = bot.getDatabase();
Member member = event.getMember();
Message message = event.getMessage();
Guild guild = event.getGuild();
String roleName = TextUtils.seekScannerToEnd(messageIterator)
.toLowerCase();
if (roleName.equals("")) {
return true;
}
List<Role> matchingRoles = guild.getRoles()
.stream()
.filter((role) -> role.getName().toLowerCase().equals(roleName))
.collect(Collectors.toList());
if (matchingRoles.size() == 0) {
DiscordUtils.failMessage(bot, message, "Could not find a role with specified name!");
return false;
}
Role matchedRole = matchingRoles.get(0);
Result<RolelistRecord> assignableRoles = database.selectFrom(Tables.ROLELIST)
.where(Tables.ROLELIST.GUILDID.eq(guild.getId()))
.and(Tables.ROLELIST.ROLEID.eq(matchedRole.getId()))
.fetch();
boolean roleExists = false;
for (RolelistRecord record: assignableRoles) {
if (record.getRoleid().equals(matchedRole.getId())) {
roleExists = true;
}
}
if (!roleExists) {
DiscordUtils.failMessage(bot, message, "This role is not self-assignable!");
return false;
}
GuildController controller = guild.getController();
try {
controller.addSingleRoleToMember(member, matchedRole).complete();
DiscordUtils.successReact(bot, message);
} catch (Exception e) {
DiscordUtils.failMessage(bot, message, "Could not assign specified role. Do I have enough permissions?");
}
return false;
}
示例8: run
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; //导入方法依赖的package包/类
@Override
public boolean run(DiscordBot bot, GuildMessageReceivedEvent event, String args) {
Scanner messageIterator = new Scanner(args);
JDA shard = event.getJDA();
Member member = event.getMember();
User user = event.getAuthor();
Message message = event.getMessage();
TextChannel channel = event.getChannel();
Guild guild = event.getGuild();
if (!member.hasPermission(Permission.KICK_MEMBERS)) {
DiscordUtils.failMessage(bot, message, "You don't have enough permissions to execute this command!");
return false;
}
if (!messageIterator.hasNext(DiscordUtils.USER_MENTION_PATTERN)) {
return true;
} else {
// advance the scanner one step to get rid of user mention
messageIterator.next();
}
User warnUser = message.getMentionedUsers().get(0);
Member warnMember = guild.getMember(warnUser);
if (user.getId().equals(warnUser.getId())) {
DiscordUtils.failMessage(bot, message, "You can't warn yourself, dummy!");
return false;
}
String reason = TextUtils.seekScannerToEnd(messageIterator);
reason = reason.equals("") ? "No reason specified" : reason;
Date now = new Date();
EmbedBuilder embed = new EmbedBuilder();
embed.setTitle("Warned in " + guild.getName());
embed.setColor(new Color(0x4286F4));
embed.setDescription("You were warned in " + guild.getName());
embed.addField("Reason:", reason, false);
embed.setFooter("Warned by " + DiscordUtils.getUserTagAndId(user), null);
embed.setTimestamp(now.toInstant());
try {
DiscordUtils.sendDM(warnUser, embed.build());
} catch (Exception e) {
DiscordUtils.sendMessage(channel, "Could not send a warning to the specified user via private message!");
}
DiscordUtils.successReact(bot, message);
DSLContext database = bot.getDatabase();
WarnlistRecord record = database.insertInto(Tables.WARNLIST,
Tables.WARNLIST.USERID,
Tables.WARNLIST.MODERATORUSERID,
Tables.WARNLIST.GUILDID,
Tables.WARNLIST.WARNTIME,
Tables.WARNLIST.REASON)
.values(warnUser.getId(),
user.getId(),
guild.getId(),
now.getTime() / 1000,
reason)
.returning(Tables.WARNLIST.ID)
.fetchOne();
DiscordUtils.createModLogEntry(bot, shard, message, warnMember, reason, "warn", record.getId(), null, false);
DiscordUtils.sendMessage(channel, "Warned " + DiscordUtils.getUserTagAndId(warnUser));
return false;
}
示例9: addTag
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; //导入方法依赖的package包/类
private void addTag(DiscordBot bot, GuildMessageReceivedEvent event, Scanner messageIterator) {
DSLContext database = bot.getDatabase();
Guild guild = event.getGuild();
Message message = event.getMessage();
Member member = event.getMember();
if (!member.hasPermission(Permission.ADMINISTRATOR)) {
DiscordUtils.failMessage(bot, message, "You don't have enough permissions to use this command!");
return;
}
if (!messageIterator.hasNext()) {
DiscordUtils.failMessage(bot, message, "Please provide a tag name and a response to create a new tag!");
return;
}
String tagName = messageIterator.next();
if (isSubcommand(tagName)) {
DiscordUtils.failMessage(bot, message, "You can't create a tag with the same name as a subcommand!");
return;
}
String response = TextUtils.seekScannerToEnd(messageIterator);
if (response.equals("")) {
DiscordUtils.failMessage(bot, message, "Empty responses aren't allowed!");
return;
}
TaglistRecord record = database.newRecord(Tables.TAGLIST);
record.setGuildid(guild.getId());
record.setName(tagName);
record.setResponse(response);
try {
record.store();
DiscordUtils.successReact(bot, message);
} catch (Exception e) {
DiscordUtils.failMessage(bot, message, "Tag `" + tagName + "` already exists!");
}
}
示例10: run
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; //导入方法依赖的package包/类
@Override
public boolean run(DiscordBot bot, GuildMessageReceivedEvent event, String args) {
Scanner messageIterator = new Scanner(args);
Member member = event.getMember();
Message message = event.getMessage();
Guild guild = event.getGuild();
Member selfMember = guild.getSelfMember();
GuildController controller = guild.getController();
if (!member.hasPermission(Permission.BAN_MEMBERS)) {
DiscordUtils.failMessage(bot, message, "You don't have enough permissions to execute this command! Required permission: Ban Members");
return false;
}
if (!selfMember.hasPermission(Permission.BAN_MEMBERS)) {
DiscordUtils.failMessage(bot, message, "I do not have enough permissions to do that!");
return false;
}
String unbanArgument = TextUtils.seekScannerToEnd(messageIterator);
if (unbanArgument.equals("")) {
return true;
}
List<User> bans = guild.getBans().complete();
User targetUser = bans.stream()
.filter((bannedUser) -> {
String tag = DiscordUtils.getTag(bannedUser);
return tag.equals(unbanArgument);
})
.findAny()
.orElse(null);
if (targetUser == null) {
DiscordUtils.failMessage(bot, message, "Could not find a banned user called `" + unbanArgument + "`!");
return false;
}
controller.unban(targetUser).complete();
DSLContext database = bot.getDatabase();
Result<BanlistRecord> records = database.selectFrom(Tables.BANLIST)
.where(Tables.BANLIST.GUILDID.eq(guild.getId()))
.and(Tables.BANLIST.USERID.eq(targetUser.getId()))
.fetch();
for (BanlistRecord record: records) {
record.setUnbanned(true);
record.update();
}
DiscordUtils.successReact(bot, message);
return false;
}
示例11: handleCustom
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; //导入方法依赖的package包/类
public void handleCustom(GuildMessageReceivedEvent event, String cmdname) {
GabrielData.GuildData data = GabrielData.guilds().getObject(event.getGuild().getId());
if(data == null) return;
CustomCommand custom = data.customCommands.get(cmdname);
if(custom == null) return;
if(!PermissionUtil.checkPermission(event.getChannel(), event.getGuild().getSelfMember(), Permission.MESSAGE_EMBED_LINKS)) {
event.getChannel().sendMessage("I need the Embed Links permission").queue();
return;
}
String rawInput = event.getMessage().getRawContent();
User user = event.getAuthor();
Member m = event.getMember();
Guild g = event.getGuild();
Message msg = event.getMessage();
TextChannel c = event.getChannel();
String input = rawInput.substring(rawInput.indexOf(cmdname)+cmdname.length()).trim();
String processed = custom.process(event, input,
"user", event.getAuthor().getName(),
"discrim", event.getAuthor().getDiscriminator(),
"mention", event.getAuthor().getAsMention(),
"channel", event.getChannel().getName(),
"userid", event.getAuthor().getId(),
"channelid", event.getChannel().getId(),
"guild", event.getGuild().getName(),
"guildid", event.getGuild().getId(),
"event.message.raw", input,
"event.message.stripped", msg.getStrippedContent(),
"event.message", msg.getContent(),
"event.author.mention", user.getAsMention(),
"event.author.username", user.getName(),
"event.author.discriminator", user.getDiscriminator(),
"event.author.name", m.getEffectiveName(),
"event.guild.name", g.getName(),
"event.guild.owner.name", g.getOwner().getEffectiveName(),
"event.guild.owner.username", g.getOwner().getUser().getName(),
"event.guild.owner.discriminator", g.getOwner().getUser().getDiscriminator(),
"event.channel.name", c.getName(),
"event.channel.topic", c.getTopic(),
"event.channel.mention", c.getAsMention()
);
if(processed == null) return;
if(processed.length() > 1990) {
processed = "Done! " + Utils.paste(processed);
}
event.getChannel().sendMessage(processed).queue();
}