本文整理汇总了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();
}
}
}
}