本文整理汇总了Java中net.dv8tion.jda.core.events.message.MessageReceivedEvent.getTextChannel方法的典型用法代码示例。如果您正苦于以下问题:Java MessageReceivedEvent.getTextChannel方法的具体用法?Java MessageReceivedEvent.getTextChannel怎么用?Java MessageReceivedEvent.getTextChannel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.dv8tion.jda.core.events.message.MessageReceivedEvent
的用法示例。
在下文中一共展示了MessageReceivedEvent.getTextChannel方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleMessages
import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //导入方法依赖的package包/类
private void handleMessages(MessageReceivedEvent event) {
String channelName = event.getChannel().getName();
String username = event.getAuthor().getName();
String message = event.getMessage().getContent();
String messageId = event.getMessage().getId();
Channel channel = event.getTextChannel();
User sender = event.getAuthor();
Boolean isAdmin = PermissionUtil.checkPermission(channel, event.getMember(), Permission.ADMINISTRATOR);
com.gmt2001.Console.out.println("[DISCORD] [#" + channelName + "] " + username.toLowerCase() + ": " + message);
// Be sure that this is commented out before a release back into the master branch!
/*
if (message.equals("!testjoin") && isAdmin) {
EventBus.instance().post(new DiscordJoinEvent(event.getMember()));
}
*/
if (message.startsWith("!")) {
commandEvent(sender, channel, message, isAdmin);
}
EventBus.instance().postAsync(new DiscordMessageEvent(sender, channel, message, messageId, isAdmin));
}
示例2: 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;
}
}
}
示例3: exampleTimeout
import net.dv8tion.jda.core.events.message.MessageReceivedEvent; //导入方法依赖的package包/类
public exampleTimeout(MessageReceivedEvent event) {
channel = event.getTextChannel();
}
示例4: 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();
}
}