本文整理匯總了Java中net.dv8tion.jda.core.entities.Message.getTextChannel方法的典型用法代碼示例。如果您正苦於以下問題:Java Message.getTextChannel方法的具體用法?Java Message.getTextChannel怎麽用?Java Message.getTextChannel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.dv8tion.jda.core.entities.Message
的用法示例。
在下文中一共展示了Message.getTextChannel方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: execute
import net.dv8tion.jda.core.entities.Message; //導入方法依賴的package包/類
@Override
protected Message execute(CommandManager.ParsedCommandInvocation parsedCommandInvocation, UserPermissions userPermissions) {
Message message = parsedCommandInvocation.getMessage();
Guild guild = message.getGuild();
TextChannel channel = message.getTextChannel();
StringBuilder rawRoles = new StringBuilder();
guild.getRoles().forEach(r -> rawRoles.append(r.getName()).append(", "));
StringBuilder roles = new StringBuilder(rawRoles.toString());
roles.replace(rawRoles.lastIndexOf(","), roles.lastIndexOf(",") + 1, "" );
EmbedBuilder serverInfo = new EmbedBuilder();
serverInfo.setColor(Colors.COLOR_PRIMARY);
serverInfo.setTitle(":desktop: Serverinfo of " + guild.getName());
serverInfo.setThumbnail(guild.getIconUrl());
serverInfo.addField("ID", "`" + guild.getId() + "`", false);
serverInfo.addField("Guildname", "`" + guild.getName() + "`", false);
serverInfo.addField("Server region", guild.getRegion().toString(), false);
serverInfo.addField("Members", String.valueOf(guild.getMembers().size()), false);
serverInfo.addField("Textchannels", String.valueOf(guild.getTextChannels().size()), false);
serverInfo.addField("Voicechannels", String.valueOf(guild.getVoiceChannels().size()), false);
serverInfo.addField("Roles", String.valueOf(guild.getRoles().size()) + "\n ```" + roles.toString() + "```", false);
serverInfo.addField("Server owner", guild.getOwner().getUser().getName() + "#" + guild.getOwner().getUser().getDiscriminator(), false);
serverInfo.addField("Server icon url", guild.getIconUrl(), false);
serverInfo.addField("Server Creation Date", guild.getCreationTime().format(DateTimeFormatter.ISO_DATE_TIME), false);
return new MessageBuilder().setEmbed(serverInfo.build()).build();
}
示例2: execute
import net.dv8tion.jda.core.entities.Message; //導入方法依賴的package包/類
@Override
protected Message execute(CommandManager.ParsedCommandInvocation parsedCommandInvocation, UserPermissions userPermissions) {
Message message = parsedCommandInvocation.getMessage();
if (message.getMentionedUsers().isEmpty())
return new MessageBuilder().setEmbed(EmbedUtil.info("Usage", "unmute <@User>").build()).build();
Member target = message.getGuild().getMember(message.getMentionedUsers().get(0));
if (!message.getGuild().getSelfMember().canInteract(target))
return new MessageBuilder().setEmbed(EmbedUtil.error("No permission", "Sorry i can't unmute this use! It's a moderator or higher").build()).build();
TextChannel channel = message.getTextChannel();
if (channel.getPermissionOverride(target) == null)
channel.createPermissionOverride(target).complete();
if (!channel.getPermissionOverride(target).getDenied().contains(Permission.MESSAGE_WRITE))
return new MessageBuilder().setEmbed(EmbedUtil.error("Not muted", "This user is no muted. Use `mute <@User>` to mute him").build()).build();
message.getGuild().getTextChannels().forEach(c -> {
if (c.getPermissionOverride(target) == null)
c.createPermissionOverride(target).complete();
c.getPermissionOverride(target).getManager().grant(Permission.MESSAGE_WRITE).queue();
});
PrivateChannel targetch = target.getUser().openPrivateChannel().complete();
targetch.sendMessage(EmbedUtil.info("Unmuted", "You got unmuted on `" + message.getGuild().getName() + "` by " + message.getAuthor().getAsMention()).build()).queue();
return new MessageBuilder().setEmbed(EmbedUtil.success("Unmuted", "Successfully Unmuted " + target.getAsMention()).build()).build();
}
示例3: execute
import net.dv8tion.jda.core.entities.Message; //導入方法依賴的package包/類
@Override
protected Message execute(CommandManager.ParsedCommandInvocation parsedCommandInvocation, UserPermissions userPermissions) {
Message message = parsedCommandInvocation.getMessage();
if (message.getMentionedUsers().isEmpty())
return new MessageBuilder().setEmbed(EmbedUtil.info("Usage", "mute <@User>").build()).build();
Member target = message.getGuild().getMember(message.getMentionedUsers().get(0));
if (!message.getGuild().getSelfMember().canInteract(target))
return new MessageBuilder().setEmbed(EmbedUtil.error("No permission", "Sorry i can't mute this user! His/her role is higher than yours.").build()).build();
TextChannel channel = message.getTextChannel();
if (channel.getPermissionOverride(target) == null)
channel.createPermissionOverride(target).complete();
if (channel.getPermissionOverride(target).getDenied().contains(Permission.MESSAGE_WRITE))
return new MessageBuilder().setEmbed(EmbedUtil.error("Already muted", "This user is already muted.").build()).build();
message.getGuild().getTextChannels().forEach(c -> {
if (c.getPermissionOverride(target) == null)
c.createPermissionOverride(target).complete();
c.getPermissionOverride(target).getManager().deny(Permission.MESSAGE_WRITE).queue();
});
PrivateChannel targetch = target.getUser().openPrivateChannel().complete();
targetch.sendMessage(EmbedUtil.info("Muted", "You got muted on `" + message.getGuild().getName() + "` by " + message.getAuthor().getAsMention()).build()).queue();
return new MessageBuilder().setEmbed(EmbedUtil.success("Muted", "Successfully muted " + target.getAsMention()).build()).build();
}
示例4: doYaThing
import net.dv8tion.jda.core.entities.Message; //導入方法依賴的package包/類
@Override
public void doYaThing(Message message) {
TextChannel channel = message.getTextChannel();
String commandNParrameters[] = DodoStringHandler.getCommandNParameters(message.getRawContent());
StringBuilder out = new StringBuilder();
try {
if (commandNParrameters.length > 1) {
for (Quote quote : Bot.quotes) {
if (quote.getWho().toLowerCase().equals(commandNParrameters[1].toLowerCase())) {
out.append(quote).append("\n");
}
}
if (out.toString().isEmpty())
channel.sendMessage("No quotes from " + commandNParrameters[1]).complete();
else
channel.sendMessage(out.toString()).complete();
} else
channel.sendMessage("```" + this.usage + "```").complete();
} catch (Exception e) {
e.printStackTrace();
}
}
示例5: doYaThing
import net.dv8tion.jda.core.entities.Message; //導入方法依賴的package包/類
@Override
public void doYaThing(Message message) {
TextChannel channel = message.getTextChannel();
String content = message.getRawContent();
List<Member> members = message.getGuild().getMembers();
try {
ArrayList<Stats> statsOfMembers = getMembers(members);
statsOfMembers.sort(new StatsComparator());
int i = 0;
for (Stats s : statsOfMembers) {
if (i > 5)
break;
for (Member m : members) {
if (m.getUser().getId().equals(s.getPresona())) {
channel.sendMessage("User: " + m.getUser().getName() + " Score: " + s.getNumOfMessages()).queue();
}
}
i++;
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例6: doYaThing
import net.dv8tion.jda.core.entities.Message; //導入方法依賴的package包/類
@Override
public void doYaThing(Message message) {
try {
TextChannel channel = message.getTextChannel();
String parameters[] = DodoStringHandler.getParameters(message.getRawContent());
BankAccount bankAccount = null;
boolean exists = false;
for (BankAccount b : bankAccounts) {
if (b.getID().equals(message.getAuthor().getId())) {
exists = true;
bankAccount = b;
}
}
if (parameters.length > 0 && exists) {
double money = Double.parseDouble(parameters[0]);
if (bankAccount.getBalance() > money) {
if ((RandomGen.rndNm(3) == 1 && money > 1000) || money > 10000) {
Stats stats = Stats.GetStats(message.getAuthor());
int calculation = (int) Math.log10(money) * getMul((int) money);
int max = RandomGen.rndNm(calculation / 2, calculation);
channel.sendMessage("*" + message.getAuthor().getName() + "'s stats magically increased by " + max + "*").complete();
if (max > 100)
max = max / 2;
for (int i = 0; i < max; i++)
stats.increase();
bankAccount.setBalance(bankAccount.getBalance() - money);
FileHandler.writeToFile(bankAccounts);
} else {
channel.sendMessage("*Takes the money* \n I ain't that cheap!!!").complete();
bankAccount.setBalance(bankAccount.getBalance() - money);
FileHandler.writeToFile(bankAccounts);
}
} else {
channel.sendMessage("You don't have the money!!").complete();
}
}
} catch (Exception e) {
message.getTextChannel().sendMessage("That's no good!").complete();
}
}
示例7: doYaThing
import net.dv8tion.jda.core.entities.Message; //導入方法依賴的package包/類
@Override
public void doYaThing(Message message) {
TextChannel textChannel = message.getTextChannel();
try {
int x = RandomGen.rndNm(2);
if (x == 0)
textChannel.sendMessage("Tails").complete();
else
textChannel.sendMessage("Heads").complete();
} catch (Exception e) {
e.printStackTrace();
}
}
示例8: doYaThing
import net.dv8tion.jda.core.entities.Message; //導入方法依賴的package包/類
@Override
public void doYaThing(Message message) {
Guild guild = message.getGuild();
TextChannel channel = message.getTextChannel();
boolean exists = false;
Admin admin = null;
for (Admin a : admins) {
if (a.getGuild().equals(guild.getId())) {
exists = true;
admin = a;
}
}
System.out.println(exists);
try {
if (exists) {
channel.sendMessage("Your guild already has an Admin: " + admin.getAdmin()).complete();
} else {
admins.add(new Admin(message.getAuthor().getId(), guild.getId()));
FileHandler.writeToFile(admins);
channel.sendMessage("Admin of " + guild.getName() + " is " + message.getAuthor().getAsMention()).complete();
}
} catch (Exception e) {
//message.getTextChannel().sendMessage(e.getMessage()).complete();
System.out.println(e.getMessage());
log.log("ERROR: " + e.getCause() + " " + e.getMessage());
}
}
示例9: onCommand
import net.dv8tion.jda.core.entities.Message; //導入方法依賴的package包/類
@Override
public boolean onCommand(Message message, String[] args) {
TextChannel channel = message.getTextChannel();
if (!message.getMentionedChannels().isEmpty()) {
channel = message.getMentionedChannels().get(0);
}
MessageFactory.makeSuccess(message, ":user :id: of the :channel channel is `:targetChannel`")
.set("targetChannel", channel.getId()).queue();
return true;
}
示例10: onCommand
import net.dv8tion.jda.core.entities.Message; //導入方法依賴的package包/類
@Override
public boolean onCommand(Message message, String[] args) {
TextChannel channel = message.getTextChannel();
if (!message.getMentionedChannels().isEmpty()) {
channel = message.getMentionedChannels().get(0);
}
String status = String.join(" ",
ONLINE + " Enabled",
DISABLED + " Disabled in Channel",
DISABLE_GLOBALLY + " Disabled Globally"
);
GuildTransformer guildTransformer = GuildController.fetchGuild(avaire, message.getGuild());
ChannelTransformer transformer = guildTransformer.getChannel(channel.getId());
List<String> items = new ArrayList<>();
for (Category category : CategoryHandler.getValues()) {
if (!transformer.isCategoryEnabledGlobally(category)) {
items.add(DISABLE_GLOBALLY + category.getName());
continue;
}
if (!transformer.isCategoryEnabled(category)) {
items.add(DISABLED + category.getName());
continue;
}
items.add(ONLINE + category.getName());
}
MessageFactory.makeInfo(message, status + "\n\n" + String.join("\n", items))
.setTitle("Command Category Status for #" + channel.getName())
.queue();
return true;
}
示例11: getLevelUpChannel
import net.dv8tion.jda.core.entities.Message; //導入方法依賴的package包/類
/**
* Gets the level up channel from the current message event and guild
* transformer, if no valid level up channel is set for the given
* guild, the message text chanel will be returned instead.
*
* @param message The message event that should be used as a default.
* @param guild The guild transformer that should be used to get the level up channel.
* @return The level up channel if one is set, otherwise the text channel from the message object.
*/
private static TextChannel getLevelUpChannel(Message message, GuildTransformer guild) {
String levelChannel = guild.getLevelChannel();
if (levelChannel == null) {
return message.getTextChannel();
}
TextChannel channel = message.getGuild().getTextChannelById(levelChannel);
return channel == null ? message.getTextChannel() : channel;
}
示例12: execute
import net.dv8tion.jda.core.entities.Message; //導入方法依賴的package包/類
@Override
protected Message execute(CommandManager.ParsedCommandInvocation parsedCommandInvocation, UserPermissions userPermissions) {
Message message = parsedCommandInvocation.getMessage();
String[] args = parsedCommandInvocation.getArgs();
TextChannel channel = message.getTextChannel();
Guild guild = message.getGuild();
if(args.length == 0){
return new MessageBuilder().setEmbed(EmbedUtil.info("Usage", "search <query>").build()).build();
}
StringBuilder query = new StringBuilder();
for (String arg : args) {
query.append(arg);
}
StringBuilder textchannels = new StringBuilder();
StringBuilder voicechannels = new StringBuilder();
StringBuilder members = new StringBuilder();
StringBuilder roles = new StringBuilder();
Message mymsg = channel.sendMessage(new EmbedBuilder().setColor(Color.cyan).setDescription("Collecting textchannels ...").build()).complete();
guild.getTextChannels().forEach(i -> {
if(i.getName().toLowerCase().contains(query.toString().toLowerCase()))
textchannels.append(i.getName() + "(`" + i.getId() + "`)").append("\n");
});
mymsg.editMessage(new EmbedBuilder().setColor(Color.cyan).setDescription("Collecting voicechannels ...").build()).queue();
guild.getVoiceChannels().forEach(i -> {
if(i.getName().toLowerCase().contains(query.toString().toLowerCase()))
voicechannels.append(i.getName() + "(`" + i.getId() + "`)").append("\n");
});
mymsg.editMessage(new EmbedBuilder().setColor(Color.cyan).setDescription("Collecting users ...").build()).queue();
guild.getMembers().forEach(i -> {
if(i.getUser().getName().toLowerCase().contains(query.toString().toLowerCase()) || i.getEffectiveName().toLowerCase().contains(query.toString().toLowerCase()))
members.append(i.getUser().getName() + "(`" + i.getUser().getId() + "`)").append("\n");
});
mymsg.editMessage(new EmbedBuilder().setColor(Color.cyan).setDescription("Collecting roles ...").build()).queue();
guild.getRoles().forEach(i -> {
if(i.getName().toLowerCase().contains(query.toString().toLowerCase()))
roles.append(i.getName() + "(`" + i.getId() + "`)").append("\n");
});
mymsg.delete().queue();
try {
EmbedBuilder results = new EmbedBuilder()
.setColor(Color.green)
.addField("**Textchannels**", textchannels.toString(), false)
.addField("**Voicechannles**", voicechannels.toString(), false)
.addField("**Members**", members.toString(), false)
.addField("**Roles**", roles.toString(), false);
return new MessageBuilder().setEmbed(results.build()).build();
} catch (IllegalArgumentException ex){
return new MessageBuilder().setEmbed(EmbedUtil.error("Error!", "Too many results!").build()).build();
}
}
示例13: onCommand
import net.dv8tion.jda.core.entities.Message; //導入方法依賴的package包/類
@Override
public boolean onCommand(Message message, String[] args) {
Channel channel = message.getTextChannel();
if (args.length > 0) {
channel = MentionableUtil.getChannel(message, args);
if (channel == null) {
return sendErrorMessage(message, "I found no channels with the name or ID of `%s`", args[0]);
}
}
Carbon time = Carbon.createFromOffsetDateTime(channel.getCreationTime());
PlaceholderMessage placeholder = MessageFactory.makeEmbeddedMessage(message.getChannel())
.setColor(MessageType.INFO.getColor())
.setTitle("#" + channel.getName())
.addField("ID", channel.getId(), true)
.addField("Position", "" + channel.getPosition(), true)
.addField("Users", "" + channel.getMembers().size(), true)
.addField("Category", getCategoryFor(channel), true);
if (channel instanceof TextChannel) {
TextChannel textChannel = (TextChannel) channel;
String topic = "*No topic has been set for this channel*";
if (textChannel.getTopic() != null && textChannel.getTopic().trim().length() > 0) {
topic = textChannel.getTopic();
}
placeholder
.setDescription(topic)
.addField("NSFW", textChannel.isNSFW() ? "ON" : "OFF", true);
}
if (channel instanceof VoiceChannel) {
VoiceChannel voiceChannel = (VoiceChannel) channel;
int bitRate = voiceChannel.getBitrate() / 1000;
placeholder
.setDescription("*This voice channel has *")
.addField("Bit Rate", bitRate + " kbps", true);
}
placeholder
.addField("Created At", time.format("EEE, dd MMM yyyy HH:mm") + "\n*About " + shortenDiffForHumans(time) + "*", true)
.queue();
return true;
}