本文整理匯總了Java中net.dv8tion.jda.core.events.message.MessageReceivedEvent.getJDA方法的典型用法代碼示例。如果您正苦於以下問題:Java MessageReceivedEvent.getJDA方法的具體用法?Java MessageReceivedEvent.getJDA怎麽用?Java MessageReceivedEvent.getJDA使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.dv8tion.jda.core.events.message.MessageReceivedEvent
的用法示例。
在下文中一共展示了MessageReceivedEvent.getJDA方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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);
}
示例2: 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);
}
}
}
}
示例3: sendMessage
import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入方法依賴的package包/類
@Override
public void sendMessage(MessageReceivedEvent event, MessageSender sender) {
JDA jda = event.getJDA();
if (event.getAuthor().isBot()) {
return;
}
GuildConfig guildConfig = null;
if (event.getChannelType().isGuild() && event.getGuild() != null) {
guildConfig = configService.getOrCreate(event.getGuild());
}
String content = event.getMessage().getRawContent().trim();
String prefix = guildConfig != null ? guildConfig.getPrefix() : configService.getDefaultPrefix();
if (event.getMessage().isMentioned(jda.getSelfUser())) {
String customMention = String.format("<@!%s>", jda.getSelfUser().getId());
prefix = content.startsWith(customMention) ? customMention : jda.getSelfUser().getAsMention();
}
if (StringUtils.isNotEmpty(content) && content.startsWith(prefix) && content.length() <= MessageEmbed.TEXT_MAX_LENGTH) {
String input = content.substring(prefix.length()).trim();
String[] args = input.split("\\s+");
if (args.length == 0) {
return;
}
input = input.substring(args[0].length(), input.length()).trim();
sender.sendCommand(event, input, args[0], guildConfig);
}
}
示例4: 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();
});
}
}