本文整理匯總了Java中net.dv8tion.jda.core.events.message.MessageReceivedEvent.getMessage方法的典型用法代碼示例。如果您正苦於以下問題:Java MessageReceivedEvent.getMessage方法的具體用法?Java MessageReceivedEvent.getMessage怎麽用?Java MessageReceivedEvent.getMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.dv8tion.jda.core.events.message.MessageReceivedEvent
的用法示例。
在下文中一共展示了MessageReceivedEvent.getMessage方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onMessageReceived
import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入方法依賴的package包/類
@Override
public void onMessageReceived(MessageReceivedEvent event) {
if (event.getAuthor().isBot())
return;
Message message = event.getMessage();
String content = message.getRawContent();
String commandNParameters[] = DodoStringHandler.getCommandNParameters(content);
try {
for (IFunction f : commands) {
if ((commandNParameters[0].equals(prefix + f.command)))
f.doYaThing(message);
}
} catch (Exception e) {
System.out.println(e.getMessage());
log.log("ERROR: " + e.getCause() + " " + e.getMessage());
}
}
示例2: 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);
}
示例3: onMessageReceived
import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入方法依賴的package包/類
/**
* NOTE THE @Override!
* This method is actually overriding a method in the ListenerAdapter class! We place an @Override annotation
* right before any method that is overriding another to guarantee to ourselves that it is actually overriding
* a method from a super class properly. You should do this every time you override a method!
* <p>
* As stated above, this method is overriding a hook method in the
* {@link net.dv8tion.jda.core.hooks.ListenerAdapter ListenerAdapter} class. It has convience methods for all JDA events!
* Consider looking through the events it offers if you plan to use the ListenerAdapter.
* <p>
* In this example, when a message is received it is printed to the console.
*
* @param event An event containing information about a {@link net.dv8tion.jda.core.entities.Message Message} that was
* sent in a channel.
*/
//All Messages recieved, from Private channels (DM), Public Channels(server/guild), Groups (Client only, we're using bot account so we can't do groups)
@Override
public void onMessageReceived(MessageReceivedEvent event) {
//These are provided with every event in JDA
JDA jda = event.getJDA(); //JDA, the core of the api.
//long responseNumber = event.getResponseNumber();//The amount of discord events that JDA has received since the last reconnect.
//Event specific information
User author = event.getAuthor(); //The user that sent the message
Message message = event.getMessage(); //The message that was received.
String msg = message.getContentDisplay(); //This returns a human readable version of the Message. Similar to
// what you would see in the client.
boolean isBotAdminOwner = isBotAdminOwner(author);
if (message.isFromType(ChannelType.TEXT)) {
if (message.isMentioned(jda.getSelfUser())) {
if (msg.contains("shutdown")) {
//Make sure we have permission
if (isBotAdminOwner) {
closeMeDown(author);
}
}
}
} else if (message.isFromType(ChannelType.PRIVATE)) {
if (msg.contains("shutdown")) {
//Make sure we have permission
if (isBotAdminOwner) {
closeMeDown(author);
}
}
}
}
示例4: onMessageReceived
import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入方法依賴的package包/類
@Override
public void onMessageReceived(MessageReceivedEvent event) {
if (event.getAuthor().isBot())
return;
Message message = event.getMessage();
String content = message.getRawContent();
User author = message.getAuthor();
try {
Stats temp = Stats.GetStats(author);
if (temp != null) {
temp.increase();
}
if (content.equals("Bot.stats(false);") && temp != null) {
stats.remove(temp);
message.addReaction("\u2705").complete();
}
if (message.getRawContent().equals("Bot.stats(true);") && temp == null) {
stats.add(new Stats(author));
message.addReaction("\u2705").complete();
message.getTextChannel().sendMessage("Use `" + prefix + "stats` to check your stats").complete();
}
if (RandomGen.rndNm(10) == 3) {
FileHandler.writeToFile(stats);
}
} catch (Exception e) {
System.out.println(e.getMessage());
log.log("ERROR: " + e.getCause() + " " + e.getMessage());
}
}
示例5: onMessage
import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入方法依賴的package包/類
@SubscribeEvent
protected void onMessage(MessageReceivedEvent event)
{
// TODO: Krobot 2.5.0, handle mentions with space / quotes / etc...
String[] line = splitWithQuotes(event.getMessage().getContent());
if (line.length == 0)
{
return;
}
for (Command command : commands)
{
if (command.getLabel().equalsIgnoreCase(line[0]))
{
if (typing)
{
event.getChannel().sendTyping().queue();
}
CommandContext context = new CommandContext(event.getAuthor(), event.getMessage(), event.getTextChannel());
List<String> args = Arrays.asList(ArrayUtils.subarray(line, 1, line.length));
try
{
command.call(context, args);
}
catch (Throwable t)
{
exHandler.handle(t, command, args, context);
}
return;
}
}
}
示例6: 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();
});
}
}
示例7: onMessageReceived
import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入方法依賴的package包/類
@Override
public void onMessageReceived(MessageReceivedEvent event)
{
if (NapBot.terminationReason != null || event.getAuthor().getIdLong() == event.getAuthor().getJDA().getSelfUser().getIdLong())
{
// don't respond to messages if the bot is shutting down, or if the messages are coming the bot itself
return;
}
try
{
if (event.isFromType(ChannelType.PRIVATE))
{
log.info("PRIVATE/{}: {}", event.getAuthor().getName(), event.getMessage().getRawContent());
event.getChannel().sendMessage("I haven't been programmed to respond to private messages O_O").complete();
}
else if (event.isFromType(ChannelType.TEXT))
{
Message message = event.getMessage();
User author = event.getAuthor();
TextChannel channel = event.getTextChannel();
String content = message.getRawContent();
if (content.startsWith(NapBot.CONFIGURATION.messagePrefix) && content.length() > NapBot.CONFIGURATION.messagePrefix.length())
{
log.info("PUBLIC/{}/{}/{}: {}", author.getName(), channel.getGuild().getName(), channel.getName(), content);
ArrayList<String> split = new ArrayList<String>(Arrays.asList(content.substring(NapBot.CONFIGURATION.messagePrefix.length()).split(" ")));
String command = split.remove(0);
ICommand icommand = commands.get(command.toLowerCase(Locale.ENGLISH));
if (icommand == null)
{
channel.sendMessage("I don't know what you mean by `" + content + "`. If you're not sure what you're doing, try typing `" + NapBot.CONFIGURATION.messagePrefix + "help`.").complete();
return;
}
if (!icommand.hasPermission(author))
{
channel.sendMessage("You don't have permission to execute that command").complete();
return;
}
if (!icommand.execute(author, channel, command, split, message))
{
channel.sendMessage("I don't know what you mean by `" + content + "`. If you're not sure what you're doing, try typing `" + NapBot.CONFIGURATION.messagePrefix + "help`.").complete();
return;
}
}
}
}
catch (Throwable t)
{
event.getChannel().sendMessage("An internal error occurred and I wasn't able to process that command. Please ask <@147356941860077568> to investigate").complete();
t.printStackTrace();
}
}