本文整理匯總了Java中net.dv8tion.jda.core.events.message.MessageReceivedEvent.getChannel方法的典型用法代碼示例。如果您正苦於以下問題:Java MessageReceivedEvent.getChannel方法的具體用法?Java MessageReceivedEvent.getChannel怎麽用?Java MessageReceivedEvent.getChannel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.dv8tion.jda.core.events.message.MessageReceivedEvent
的用法示例。
在下文中一共展示了MessageReceivedEvent.getChannel方法的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包/類
@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();
});
}
}
示例3: onMessageReceived
import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入方法依賴的package包/類
@Override
public void onMessageReceived(MessageReceivedEvent event) {
String message = event.getMessage().getContentDisplay();
MessageChannel channel = event.getChannel();
User author = event.getAuthor();
if ( (channel == controlChannel || channel.getType() == ChannelType.PRIVATE) && message.startsWith(Config.get(Config.COMMAND_PREFIX)) && (!author.getId().equals(api.getSelfUser().getId())) ) {
Log.debug("Got command from {}: {}", author.getName(), message);
String[] cmdarg = message.substring(Config.get(Config.COMMAND_PREFIX).length()).split(" ", 2);
String cmd = cmdarg[0];
String arg;
try {
arg = cmdarg[1];
} catch (IndexOutOfBoundsException e) {
arg = null;
}
boolean commandFound = false;
for(Command command : Command.commands) {
if (command.compare(cmd)) {
commandFound = true;
if(command.hasPermission(author)) {
command.execute(arg, author, channel, guild);
} else {
channel.sendMessage(author.getAsMention() + " ``You are not allowed to use this command.``").queue();
}
break;
}
}
if(commandFound) {
return;
}
channel.sendMessage(author.getAsMention() + " ``Unknown command``").queue();
}
}
示例4: onMessageReceived
import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //導入方法依賴的package包/類
@Override
public void onMessageReceived(MessageReceivedEvent event) {
CoreConfig config = this.phononPlugin.getConfigAdapter(CoreModule.ID, CoreConfigAdapter.class).get().getNodeOrDefault();
if (event.getMessage().getRawContent().startsWith(config.getPrefix()) && !event.getMessage().getAuthor().isBot()) {
DiscordCommandSource source = new DiscordCommandSource(event.getAuthor(), event.getChannel());
int end = event.getMessage().getRawContent().indexOf(" ");
String commandName;
String arguments;
if (end == -1) {
commandName = event.getMessage().getRawContent().substring(1);
arguments = "";
} else {
commandName = event.getMessage().getRawContent().substring(1, end);
arguments = event.getMessage().getRawContent().substring(end + 1);
}
if (aliases.containsKey(commandName)) {
IDiscordCommand command = aliases.get(commandName);
CommandElement args= null;
try {
CommandArgs commandArgs = new CommandArgs(arguments,
InputTokenizer.quotedStrings(false).tokenize(arguments, true));
CommandContext context = new CommandContext();
args = GenericArguments.seq(command.getArgs());
args.parse(source, commandArgs, context);
if (commandArgs.hasNext()) {
commandArgs.next();
throw commandArgs.createError(t("Invalid arguments!"));
}
command.execute(event.getAuthor(), context, event.getChannel());
} catch (ArgumentParseException e) {
String message = "Invalid Arguments";
if (e.getMessage() != null) {
message = e.getMessage();
}
if (args == null) {
event.getChannel().sendMessage(message).queue();
} else {
event.getChannel().sendMessage(message + System.lineSeparator() +
config.getPrefix() + commandName + args.getUsage(source).toPlain()).queue();
}
}
if (!(event.getChannel() instanceof PrivateChannel)) {
event.getMessage().delete().queue();
}
}
}
}