本文整理汇总了Java中net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent类的典型用法代码示例。如果您正苦于以下问题:Java GuildMessageReceivedEvent类的具体用法?Java GuildMessageReceivedEvent怎么用?Java GuildMessageReceivedEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GuildMessageReceivedEvent类属于net.dv8tion.jda.core.events.message.guild包,在下文中一共展示了GuildMessageReceivedEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onGuildMessageReceived
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; //导入依赖的package包/类
public void onGuildMessageReceived(GuildMessageReceivedEvent event) {
if (event.getMessage().getMentionedUsers().size() < 1) return;
if (event.getMessage().getMentionedUsers().get(0).equals(event.getJDA().getSelfUser())) {
if (!SQL.ifGuildExists(event.getGuild())) {SQL.createServer(event.getGuild());}
event.getChannel().sendMessage("Try **" + SQL.getValue(event.getGuild(), "prefix") + "help** for Help.").queue();
}
if (event.getAuthor().isBot()) return;
if (event.getAuthor().equals(event.getJDA().getSelfUser())) return;
Guild g = event.getGuild();
User user = event.getMessage().getMentionedUsers().get(0);
String us = event.getGuild().getMember(user).getOnlineStatus().toString();
if (event.getMessage().getMentionedUsers().size() < 1) return;
if (SQL.getValue(g, "msg").equals("0")) return;
if (!us.equals("ONLINE")){
Message msg = event.getChannel().sendMessage("Hey, " + event.getAuthor().getAsMention() + " " + event.getMessage().getMentionedUsers().get(0).getAsMention() + " is " + us + " you can wait long to get an Answer!").complete();
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
msg.delete().queue();
}else return;
}
示例2: process
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; //导入依赖的package包/类
public boolean process(GuildMessageReceivedEvent event, String cmdname, String content) {
Command cmd = commands.get(cmdname);
if (cmd == null) return false;
if (!cmd.permission().test(event.getMember())) {
event.getChannel().sendMessage(EmoteReference.STOP + "You have no permissions to trigger this command").queue();
return false;
}
try {
cmd.run(event, cmdname, content);
return true;
} catch (Throwable t) {
LOGGER.error("Error running command " + cmdname, t);
event.getChannel().sendMessage("There was an unexpected " + t.getClass().getSimpleName() + " running the command").queue();
return false;
}
}
示例3: 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;
}
示例4: onEvent
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; //导入依赖的package包/类
@Listener
@Override
public void onEvent(Event event) {
if (event instanceof ShardMonitorEvent) {
((ShardMonitorEvent) event).alive(shardId, ShardMonitorEvent.COMMAND_LISTENER);
return;
}
if (event instanceof GuildMessageReceivedEvent) {
GuildMessageReceivedEvent e = (GuildMessageReceivedEvent) event;
Async.thread("CmdThread", () -> onCommand(e));
// if (random.nextInt(150) > 100) {
// if (((GuildMessageReceivedEvent) event).getMember() == null) return;
// Player player = MantaroData.db().getPlayer(((GuildMessageReceivedEvent) event).getMember());
// if (player != null) {
//
// player.getData().setExperience(player.getData().getExperience() + Math.round(random.nextInt(6)));
// if (player.getData().getExperience() > (player.getLevel() * Math.log10(player.getLevel()) * 1000)) {
// player.setLevel(player.getLevel() + 1);
// }
// player.saveAsync();
// }
// }
}
}
示例5: onEvent
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; //导入依赖的package包/类
@Override
public void onEvent(Event e) {
if(!(e instanceof GuildMessageReceivedEvent)) return;
GuildMessageReceivedEvent event = (GuildMessageReceivedEvent)e;
if(event.getAuthor().equals(event.getJDA().getSelfUser())) return;
long channelId = event.getChannel().getIdLong();
RunningOperation o = OPERATIONS.get(channelId);
if(o == null) return;
int i = o.operation.run(event);
if(i == Operation.COMPLETED) {
OPERATIONS.remove(channelId);
o.future.complete(null);
} else if(i == Operation.RESET_TIMEOUT) {
OPERATIONS.resetExpiration(channelId);
}
}
示例6: onMessage
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; //导入依赖的package包/类
@Override
protected boolean onMessage(GuildMessageReceivedEvent event) {
String msg = event.getMessage().getContent();
if(triesLeft-- == 0) {
say("Max number of attempts reached! The correct answer was `" + answer + "`");
return true;
}
if(msg.replace("\\s+", " ").equalsIgnoreCase(answer)) {
say("Correct! You won 50 credits");
GabrielData.UserData user = GabrielData.users().getObject(event.getAuthor().getId());
if(user == null) {
GabrielData.users().setObject(event.getAuthor().getId(), user = new GabrielData.UserData());
}
user.money += 50;
return true;
}
say(String.format(wrongMessage(), triesLeft));
return false;
}
示例7: action
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; //导入依赖的package包/类
@Override
public void action(String[] args, GuildMessageReceivedEvent event) throws ParseException, IOException {
if (event.getGuild().getOwner().getUser().getId().equals("221905671296253953")) {
if (core.permissionHandler.check(1, event)) return;
}else if (core.permissionHandler.check(4, event)) return;
event.getMessage().delete().queue();
event.getChannel().sendMessage(":battery: System going down!").queue();
try {
Thread.sleep(7000);
} catch (InterruptedException e) {
e.printStackTrace();
}
new Timer().schedule(new TimerTask() {
@Override
public void run() {
System.exit(0);
}
}, 1000);
}
示例8: onEvent
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; //导入依赖的package包/类
@Override
public void onEvent(Event event) {
if (event instanceof GuildMessageReceivedEvent) {
final GuildMessageReceivedEvent guildMessageReceivedEvent = (GuildMessageReceivedEvent) event;
if (guildMessageReceivedEvent.getAuthor().isBot()) {
return;
}
final String rawContent = guildMessageReceivedEvent.getMessage().getRawContent();
if (rawContent.matches(minusXRegExp)) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("It would seem this is a - command to remove signups: " + rawContent);
}
String strippedContent = rawContent.replaceAll("\\s{2,4}", " ")
.replaceFirst("[-]", "");
String[] splitArguments = strippedContent.split("\\s{1}");
attemptUnsignFromMinusCommand(guildMessageReceivedEvent, splitArguments);
}
}
}
示例9: closeVote
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; //导入依赖的package包/类
private void closeVote(GuildMessageReceivedEvent event){
Message message = event.getMessage();
User author = event.getAuthor();
if(!polls.containsKey(event.getGuild())){
message("There is currently no poll running on this guild", Color.red);
return;
}
Poll poll = polls.get(event.getGuild());
if(core.permissionHandler.check(2,event)){
return;
}
polls.remove(event.getGuild());
channel.sendMessage(getParsedPoll(poll, event.getGuild()).build()).queue();
message(":white_check_mark: Poll was closed by" + event.getAuthor().getAsMention(), new Color(0x3AD70E));
Message pollmsg = channel.getMessageById(String.valueOf(poll.pollmsg)).complete();
try {
pollmsg.delete().queue();
} catch (ErrorResponseException e){
//This is an empty Catch Block
}
}
示例10: onGuildMessageReceived
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; //导入依赖的package包/类
@Override
public void onGuildMessageReceived(GuildMessageReceivedEvent e) {
if (e.getAuthor().isBot()) {
return;
}
String[] syntax = e.getMessage().getContent().split("\\s+");
if (!syntax[0].equalsIgnoreCase(Lib.PREFIX + "discord")) {
return;
}
if (syntax[1].equalsIgnoreCase("tanya")) {
e.getChannel().sendMessage("Zitat Tanya:" +
"\n`Ich weiß schon, was du meinst, aber nachdem das Problem bei Google lag und unsere Login-Server von Millionen von kleinen Wumpusen betrieben werden, hat es dann doch ganz gut geklappt. : )`")
.queue();
}
if (syntax[1].equalsIgnoreCase("twitter")) {
String zitat = zitate.get(new Random().nextInt(zitate.size()));
e.getChannel().sendMessage(new EmbedBuilder().addField("Zitat von Twitter:",zitat,false).setAuthor("Twitter","https://twitter.com",TWITTER).build()).queue();
}
}
示例11: onGuildMessageReceived
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; //导入依赖的package包/类
public void onGuildMessageReceived(GuildMessageReceivedEvent event) {
String en = SQL.getValue(event.getGuild(),"joinchannel");
Timer timer = new Timer();
Date date=new Date();
if (!event.getAuthor().isBot() && event.getAuthor().getId() != event.getJDA().getSelfUser().getId()) {
count++;
}
timer.schedule(new TimerTask(){
public void run(){
if (!en.equals("0")) {
event.getJDA().getTextChannelById(en).sendMessage("Today i count " + count + " Messages!").queue();
}
}
},date, 24*60*60*1000);
}
示例12: waitForChannel
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; //导入依赖的package包/类
private void waitForChannel(CommandEvent event)
{
waiter.waitForEvent(GuildMessageReceivedEvent.class,
e -> e.getAuthor().equals(event.getAuthor()) && e.getChannel().equals(event.getChannel()),
e -> {
if(e.getMessage().getRawContent().equalsIgnoreCase("cancel"))
{
event.replyWarning("Alright, I guess we're not having a giveaway after all..."+CANCEL);
}
else
{
String query = e.getMessage().getRawContent().replace(" ", "_");
List<TextChannel> list = FinderUtil.findTextChannels(query, event.getGuild());
if(list.isEmpty())
{
event.replyWarning("Uh oh, I couldn't find any channels called '"+query+"'! Try again!"+CHANNEL);
waitForChannel(event);
}
else if(list.size()>1)
{
event.replyWarning("Oh... there are multiple channels with that name. Please be more specific!"+CHANNEL);
waitForChannel(event);
}
else
{
TextChannel tchan = list.get(0);
if(!Constants.canSendGiveaway(tchan))
{
event.replyWarning("Erm, I need the following permissions to start a giveaway in "+tchan.getAsMention()+":\n"+Constants.PERMS+"\nPlease fix this and then try again."+CANCEL);
}
else
{
event.replySuccess("Sweet! The giveaway will be in "+tchan.getAsMention()+"! Next, how long should the giveaway last?"+TIME);
waitForTime(event, tchan);
}
}
}
},
2, TimeUnit.MINUTES, () -> event.replyWarning("Uh oh! You took longer than 2 minutes to respond, "+event.getAuthor().getAsMention()+"!"+CANCEL));
}
示例13: waitForWinners
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; //导入依赖的package包/类
private void waitForWinners(CommandEvent event, TextChannel tchan, int seconds)
{
waiter.waitForEvent(GuildMessageReceivedEvent.class,
e -> e.getAuthor().equals(event.getAuthor()) && e.getChannel().equals(event.getChannel()),
e -> {
if(e.getMessage().getRawContent().equalsIgnoreCase("cancel"))
{
event.replyWarning("Alright, I guess we're not having a giveaway after all..."+CANCEL);
}
else
{
try {
int num = Integer.parseInt(e.getMessage().getRawContent().trim());
if(num<1 || num>15)
{
event.replyWarning("Hey! I can only support 1 to 15 winners!"+WINNERS);
waitForWinners(event, tchan, seconds);
}
else
{
event.replySuccess("Ok! "+num+" winners it is! Finally, what do you want to give away?"+PRIZE);
waitForPrize(event, tchan, seconds, num);
}
} catch(NumberFormatException ex) {
event.replyWarning("Uh... that doesn't look like a valid number."+WINNERS);
waitForWinners(event, tchan, seconds);
}
}
},
2, TimeUnit.MINUTES, () -> event.replyWarning("Uh oh! You took longer than 2 minutes to respond, "+event.getAuthor().getAsMention()+"!"+CANCEL));
}
示例14: execute
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; //导入依赖的package包/类
public void execute(GuildMessageReceivedEvent e, String query) {
final AudioHandler player = JukeBot.getPlayer(e.getGuild().getAudioManager());
if (!player.isPlaying()) {
e.getChannel().sendMessage(new EmbedBuilder()
.setColor(JukeBot.embedColour)
.setTitle("No playback activity")
.setDescription("There's nothing playing.")
.build()
).queue();
return;
}
if (!permissions.isElevatedUser(e.getMember(), true)) {
e.getChannel().sendMessage(new EmbedBuilder()
.setColor(JukeBot.embedColour)
.setTitle("Permission Error")
.setDescription("You need to have the DJ role!")
.build()
).queue();
return;
}
player.getQueue().clear();
player.playNext();
}
示例15: of
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; //导入依赖的package包/类
public static CustomCommand of(GuildMessageReceivedEvent event, String text) {
String lower = text.toLowerCase();
if (lower.startsWith(PREFIX_EMBED) && lower.length() > PREFIX_EMBED.length()) {
return new EmbedCustomCommand(text.substring(PREFIX_EMBED.length()));
} else if (lower.startsWith(PREFIX_CODE) && lower.length() > PREFIX_CODE.length()) {
return CodeCustomCommand.of(event, text.substring(PREFIX_CODE.length()));
} else if (lower.startsWith(PREFIX_LUA) && lower.length() > PREFIX_LUA.length()) {
return new LuaCustomCommand(text.substring(PREFIX_LUA.length()));
} else {
return new TextCustomCommand(text);
}
}