本文整理汇总了Java中net.dv8tion.jda.core.exceptions.PermissionException类的典型用法代码示例。如果您正苦于以下问题:Java PermissionException类的具体用法?Java PermissionException怎么用?Java PermissionException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PermissionException类属于net.dv8tion.jda.core.exceptions包,在下文中一共展示了PermissionException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: pagination
import net.dv8tion.jda.core.exceptions.PermissionException; //导入依赖的package包/类
private void pagination(Message message, int pageNum)
{
waiter.waitForEvent(MessageReactionAddEvent.class, (MessageReactionAddEvent event) -> {
if(!event.getMessageId().equals(message.getId()))
return false;
if(!(LEFT.equals(event.getReactionEmote().getName())
|| STOP.equals(event.getReactionEmote().getName())
|| RIGHT.equals(event.getReactionEmote().getName())))
return false;
return isValidUser(event.getUser(), event.getGuild());
}, event -> {
int newPageNum = pageNum;
switch(event.getReactionEmote().getName())
{
case LEFT: if(newPageNum>1) newPageNum--; break;
case RIGHT: if(newPageNum<urls.size()) newPageNum++; break;
case STOP: finalAction.accept(message); return;
}
try{event.getReaction().removeReaction(event.getUser()).queue();}catch(PermissionException e){}
int n = newPageNum;
message.editMessage(renderPage(newPageNum)).queue(m -> {
pagination(m, n);
});
}, timeout, unit, () -> finalAction.accept(message));
}
开发者ID:JDA-Applications,项目名称:JDA-Utilities,代码行数:26,代码来源:Slideshow.java
示例2: joinInVoiceChannel
import net.dv8tion.jda.core.exceptions.PermissionException; //导入依赖的package包/类
public Message joinInVoiceChannel() {
if (!isMemberInVoiceChannel())
return message(error("Error!", "To use this command you have to be in a voice channel."));
VoiceChannel voiceChannel;
if (isChannelLockActivated()) {
voiceChannel = getLockedChannel();
if (voiceChannel == null)
return message(error("Error!", "Predefined channel doesn't exist."));
} else {
voiceChannel = parsedCommandInvocation.getMember().getVoiceState().getChannel();
if (isBotInVoiceChannel()) {
if (getBotsVoiceChannel() == voiceChannel)
return message(error("Error!", "Bot is already in your voice channel."));
}
}
guild.getAudioManager().setSendingHandler(getMusicManager(guild).getSendHandler());
try {
guild.getAudioManager().openAudioConnection(voiceChannel);
} catch (PermissionException e) {
if (e.getPermission() == Permission.VOICE_CONNECT) {
return message(error("Error!", "I need the VOICE_CONNECT permissions to join a channel."));
}
}
guild.getAudioManager().setSelfDeafened(true);
return EmbedUtil.message(success("Joined channel", "Joined `" + voiceChannel.getName() + "`"));
}
开发者ID:Rubicon-Bot,项目名称:Rubicon,代码行数:27,代码来源:MusicManager.java
示例3: sendPrivateMsg
import net.dv8tion.jda.core.exceptions.PermissionException; //导入依赖的package包/类
/**
* sends a message to a private message channel, opening the channel before use
*, asynchronous (non-blocking)
* @param content the message to send as a string
* @param user the user to send the private message to
* @param action a non null Consumer will do operations on the results returned
*/
public static void sendPrivateMsg(String content, User user, Consumer<Message> action )
{
if (content.isEmpty()) return;
if (user.isBot()) return;
try
{
user.openPrivateChannel().queue(privateChannel -> sendMsg(content, privateChannel, action), null);
}
catch (PermissionException ignored) { }
catch (Exception e)
{
Logging.exception( MessageUtilities.class, e );
}
}
开发者ID:notem,项目名称:Saber-Bot,代码行数:23,代码来源:MessageUtilities.java
示例4: UserVariables
import net.dv8tion.jda.core.exceptions.PermissionException; //导入依赖的package包/类
/**
* Creates a variable collection and registers events.
*/
public UserVariables() {
registerVariableEvent(userNickname, variable -> {
TextChannel channel = variable.getEnvironment().getChannel();
String nickname = variable.getVariable().value().toString();
if(nickname.length() < Limits.NICKNAME_MIN.getLimit()
|| nickname.length() > Limits.NICKNAME_MAX.getLimit()) {
Message.ZEUS_ERROR_NICKNAME_LENGTH.send(channel, Limits.NICKNAME_MIN.asString(),
Limits.NICKNAME_MAX.asString()).queue();
} else {
try {
GuildController controller = variable.getEnvironment().getGuild().getController();
controller.setNickname(variable.getEnvironment().getMember(), variable.getVariable().value().toString()).reason("Script").queue();
} catch(PermissionException exception) {
UZeus.error(channel, variable.getLineNumber(), Message.ZEUS_ERROR_NICKNAME_PERMISSION.getContent(channel));
}
}
});
}
开发者ID:Arraying,项目名称:Arraybot,代码行数:22,代码来源:UserVariables.java
示例5: manageRole
import net.dv8tion.jda.core.exceptions.PermissionException; //导入依赖的package包/类
/**
* Manages the a role.
* @param user The user.
* @param role The role.
* @param add True = add role, false = remove role.
*/
private void manageRole(Long user, Long role, Boolean add) {
try {
Guild guild = environment.getGuild();
Member member = guild.getMemberById(user);
Role roleObject = guild.getRoleById(role);
if(member == null
|| roleObject == null) {
return;
}
if(add) {
guild.getController().addSingleRoleToMember(member, roleObject).queue();
} else {
guild.getController().removeSingleRoleFromMember(member, roleObject).queue();
}
} catch(PermissionException | IllegalArgumentException exception) {
UZeus.errorInChannel(environment.getChannel(), exception);
}
}
开发者ID:Arraying,项目名称:Arraybot,代码行数:25,代码来源:RoleMethods.java
示例6: message_channel
import net.dv8tion.jda.core.exceptions.PermissionException; //导入依赖的package包/类
/**
* Messages the current channel.
* @param message The message.
*/
@ZeusMethod
public void message_channel(Object message) {
if(messagesSent > messageLimit) {
if(messagesSent == messageLimit + 1) {
UZeus.errorInChannel(environment.getChannel(), new Exception(Message.ZEUS_ERROR_RATELIMIT.getContent(environment.getChannel())));
}
messagesSent++;
return;
}
try {
environment.getChannel().sendMessage(message.toString()).queue();
} catch(PermissionException | VerificationLevelException | IllegalArgumentException exception) {
UZeus.errorInChannel(environment.getChannel(), exception);
}
messagesSent++;
}
开发者ID:Arraying,项目名称:Arraybot,代码行数:21,代码来源:MessageMethods.java
示例7: message_channel_other
import net.dv8tion.jda.core.exceptions.PermissionException; //导入依赖的package包/类
/**
* Messages another channel.
* @param id The channel ID.
* @param message The message.
*/
@ZeusMethod
public void message_channel_other(Long id, Object message) {
if(messagesSent > messageLimit) {
if(messagesSent == messageLimit + 1) {
UZeus.errorInChannel(environment.getChannel(), new Exception(Message.ZEUS_ERROR_RATELIMIT.getContent(environment.getChannel())));
}
messagesSent++;
return;
}
TextChannel channel = environment.getGuild().getTextChannelById(id);
if(channel == null) {
return;
}
try {
channel.sendMessage(message.toString()).queue();
} catch(PermissionException | VerificationLevelException | IllegalArgumentException exception) {
UZeus.errorInChannel(environment.getChannel(), exception);
}
messagesSent++;
}
开发者ID:Arraying,项目名称:Arraybot,代码行数:26,代码来源:MessageMethods.java
示例8: message_private
import net.dv8tion.jda.core.exceptions.PermissionException; //导入依赖的package包/类
/**
* Messages a private channel.
* @param id The user's ID.
* @param message The message.
*/
@ZeusMethod
public void message_private(Long id, Object message) {
if(messagesSent > messageLimit) {
if(messagesSent == messageLimit + 1) {
UZeus.errorInChannel(environment.getChannel(), new Exception(Message.ZEUS_ERROR_RATELIMIT.getContent(environment.getChannel())));
}
messagesSent++;
return;
}
Member member = environment.getGuild().getMemberById(id);
if(member == null) {
return;
}
try {
member.getUser().openPrivateChannel().queue(channel -> channel.sendMessage(message.toString()).queue());
} catch(PermissionException | VerificationLevelException | IllegalArgumentException exception) {
UZeus.errorInChannel(environment.getChannel(), exception);
}
messagesSent++;
}
开发者ID:Arraying,项目名称:Arraybot,代码行数:26,代码来源:MessageMethods.java
示例9: message_channel_embed
import net.dv8tion.jda.core.exceptions.PermissionException; //导入依赖的package包/类
/**
* Messages the current channel.
* @param embed The embed ID.
*/
@ZeusMethod
public void message_channel_embed(String embed) {
if(messagesSent > messageLimit) {
if(messagesSent == messageLimit + 1) {
UZeus.errorInChannel(environment.getChannel(), new Exception(Message.ZEUS_ERROR_RATELIMIT.getContent(environment.getChannel())));
}
messagesSent++;
return;
}
try {
EmbedBuilder embedBuilder = methods.getEmbeds().get(embed);
if(embedBuilder != null) {
environment.getChannel().sendMessage(embedBuilder.build()).queue();
}
} catch(PermissionException | VerificationLevelException | IllegalArgumentException exception) {
UZeus.errorInChannel(environment.getChannel(), exception);
}
messagesSent++;
}
开发者ID:Arraying,项目名称:Arraybot,代码行数:24,代码来源:MessageMethods.java
示例10: message_private_embed
import net.dv8tion.jda.core.exceptions.PermissionException; //导入依赖的package包/类
/**
* Messages a private channel.
* @param id The user's ID.
* @param embed The embed.
*/
@ZeusMethod
public void message_private_embed(Long id, String embed) {
if(messagesSent > messageLimit) {
if(messagesSent == messageLimit + 1) {
UZeus.errorInChannel(environment.getChannel(), new Exception(Message.ZEUS_ERROR_RATELIMIT.getContent(environment.getChannel())));
}
messagesSent++;
return;
}
Member member = environment.getGuild().getMemberById(id);
if(member == null) {
return;
}
try {
EmbedBuilder embedBuilder = methods.getEmbeds().get(embed);
if(embed != null) {
member.getUser().openPrivateChannel().queue(channel -> channel.sendMessage(embedBuilder.build()).queue());
}
} catch(PermissionException | VerificationLevelException | IllegalArgumentException exception) {
UZeus.errorInChannel(environment.getChannel(), exception);
}
messagesSent++;
}
开发者ID:Arraying,项目名称:Arraybot,代码行数:29,代码来源:MessageMethods.java
示例11: punish
import net.dv8tion.jda.core.exceptions.PermissionException; //导入依赖的package包/类
/**
* Punishes a user.
* @param id The ID of the user.
* @param reason The punishment reason.
* @param ban True = ban, false = kick.
*/
private void punish(Long id, String reason, Boolean ban) {
Member member = environment.getGuild().getMemberById(id);
TextChannel channel = environment.getChannel();
if(member == null) {
return;
}
if(reason.length() > Limits.REASON.getLimit()) {
Message.ZEUS_ERROR_BAN_REASON_LENGTH.send(channel, Limits.REASON.asString()).queue();
return;
}
try {
if(ban) {
member.getGuild().getController().ban(String.valueOf(id), 0, reason).queue();
} else {
member.getGuild().getController().kick(String.valueOf(id), reason).queue();
}
} catch(PermissionException | IllegalArgumentException | GuildUnavailableException exception) {
UZeus.errorInChannel(environment.getChannel(), exception);
}
}
开发者ID:Arraying,项目名称:Arraybot,代码行数:27,代码来源:UserMethods.java
示例12: assignAutoRole
import net.dv8tion.jda.core.exceptions.PermissionException; //导入依赖的package包/类
/**
* Applies the autorole to the specified member.
* @param member The member.
*/
private void assignAutoRole(Member member) {
Guild guild = member.getGuild();
long guildId = guild.getIdLong();
GuildEntry entry = (GuildEntry) Category.GUILD.getEntry();
boolean apply = Boolean.valueOf(entry.fetch(entry.getField(GuildEntry.Fields.AUTOROLE_ENABLED), guildId, null));
if(!apply) {
return;
}
String roleId = entry.fetch(entry.getField(GuildEntry.Fields.AUTOROLE_ROLE), guildId, null);
Role role = guild.getRoleById(roleId);
if(role == null) {
return;
}
try {
guild.getController().addSingleRoleToMember(member, role).queue();
} catch(PermissionException exception) {
logger.warn("Could not apply the autorole in the guild {} due to a permission error.", guildId);
}
}
开发者ID:Arraying,项目名称:Arraybot,代码行数:24,代码来源:MemberListener.java
示例13: manageMute
import net.dv8tion.jda.core.exceptions.PermissionException; //导入依赖的package包/类
/**
* Applies or removes the muted role to the specified user.
* This method is used to permanently mute.
* @param guild The guild.
* @param punishedId The ID of the muted user.
* @param apply True: adds role, false: removes role.
* @return A pair of success and whether the punishment needs to be revoked.
*/
private static Pair<Boolean, Boolean> manageMute(Guild guild, long punishedId, boolean apply) {
GuildEntry entry = (GuildEntry) Category.GUILD.getEntry();
String mutedRoleId = entry.fetch(entry.getField(GuildEntry.Fields.MUTE_ROLE), guild.getIdLong(), null);
Member muted = guild.getMemberById(punishedId);
Role mutedRole = guild.getRoleById(mutedRoleId);
if(muted == null
|| mutedRole == null) {
return new Pair<>(false, false);
}
try {
if(apply) {
guild.getController().addSingleRoleToMember(muted, mutedRole).queue();
} else {
guild.getController().removeSingleRoleFromMember(muted, mutedRole).queue();
}
return new Pair<>(true, false);
} catch(PermissionException exception) {
return new Pair<>(false, false);
}
}
开发者ID:Arraying,项目名称:Arraybot,代码行数:29,代码来源:UPunishment.java
示例14: startRaidMode
import net.dv8tion.jda.core.exceptions.PermissionException; //导入依赖的package包/类
public boolean startRaidMode(Guild guild, Message iniator)
{
if(raidmode.keySet().contains(guild.getId()))
return false;
raidmode.put(guild.getId(), new StringBuilder("Disabled Raid Mode. Users kicked:\n"));
if(iniator==null)
{
scheduleRaidModeCheck(guild);
modlog.logEmbed(guild, new EmbedBuilder()
.setColor(guild.getSelfMember().getColor())
.setDescription("Raid mode automatically enabled. Verification will be set to maximum if possible, and any user that joins will be kicked.")
.setTimestamp(OffsetDateTime.now())
.setFooter(guild.getJDA().getSelfUser().getName()+" automod", guild.getJDA().getSelfUser().getEffectiveAvatarUrl())
.build());
}
else
modlog.logCommand(iniator);
try{
guild.getManager().setVerificationLevel(Guild.VerificationLevel.HIGH).queue();
} catch(PermissionException ex){}
return true;
}
开发者ID:jagrosh,项目名称:Vortex,代码行数:23,代码来源:AutoMod.java
示例15: updateTopic
import net.dv8tion.jda.core.exceptions.PermissionException; //导入依赖的package包/类
public void updateTopic(long guildId, AudioHandler handler)
{
Guild guild = jda.getGuildById(guildId);
if(guild==null)
return;
TextChannel tchan = guild.getTextChannelById(getSettings(guild).getTextId());
if(tchan!=null && guild.getSelfMember().hasPermission(tchan, Permission.MANAGE_CHANNEL))
{
String otherText;
if(tchan.getTopic()==null || tchan.getTopic().isEmpty())
otherText = "\u200B";
else if(tchan.getTopic().contains("\u200B"))
otherText = tchan.getTopic().substring(tchan.getTopic().lastIndexOf("\u200B"));
else
otherText = "\u200B\n "+tchan.getTopic();
String text = FormatUtil.topicFormat(handler, guild.getJDA())+otherText;
if(!text.equals(tchan.getTopic()))
try {
tchan.getManager().setTopic(text).queue();
} catch(PermissionException e){}
}
}
开发者ID:jagrosh,项目名称:MusicBot,代码行数:23,代码来源:Bot.java
示例16: QueueCmd
import net.dv8tion.jda.core.exceptions.PermissionException; //导入依赖的package包/类
public QueueCmd(Bot bot)
{
super(bot);
this.name = "queue";
this.help = "shows the current queue";
this.arguments = "[pagenum]";
this.aliases = new String[]{"list"};
this.bePlaying = true;
this.botPermissions = new Permission[]{Permission.MESSAGE_ADD_REACTION,Permission.MESSAGE_EMBED_LINKS};
builder = new PaginatorBuilder()
.setColumns(1)
.setFinalAction(m -> {try{m.clearReactions().queue();}catch(PermissionException e){}})
.setItemsPerPage(10)
.waitOnSinglePage(false)
.useNumberedItems(true)
.showPageNumbers(true)
.setEventWaiter(bot.getWaiter())
.setTimeout(1, TimeUnit.MINUTES);
}
开发者ID:jagrosh,项目名称:MusicBot,代码行数:20,代码来源:QueueCmd.java
示例17: GuildlistCommand
import net.dv8tion.jda.core.exceptions.PermissionException; //导入依赖的package包/类
public GuildlistCommand(EventWaiter waiter)
{
this.name = "guildlist";
this.help = "shows the list of guilds the bot is on";
this.arguments = "[pagenum]";
this.botPermissions = new Permission[]{Permission.MESSAGE_EMBED_LINKS, Permission.MESSAGE_ADD_REACTION};
this.guildOnly = false;
this.ownerCommand = true;
pbuilder = new PaginatorBuilder().setColumns(1)
.setItemsPerPage(10)
.showPageNumbers(true)
.waitOnSinglePage(false)
.useNumberedItems(false)
.setFinalAction(m -> {
try {
m.clearReactions().queue();
} catch(PermissionException ex) {
m.delete().queue();
}
})
.setEventWaiter(waiter)
.setTimeout(1, TimeUnit.MINUTES);
}
开发者ID:JDA-Applications,项目名称:JDA-Utilities,代码行数:24,代码来源:GuildlistCommand.java
示例18: pagination
import net.dv8tion.jda.core.exceptions.PermissionException; //导入依赖的package包/类
private void pagination(Message message, int pageNum)
{
waiter.waitForEvent(MessageReactionAddEvent.class, (MessageReactionAddEvent event) -> {
if(!event.getMessageId().equals(message.getId()))
return false;
if(!(LEFT.equals(event.getReactionEmote().getName())
|| STOP.equals(event.getReactionEmote().getName())
|| RIGHT.equals(event.getReactionEmote().getName())))
return false;
return isValidUser(event.getUser(), event.getGuild());
}, event -> {
int newPageNum = pageNum;
switch(event.getReactionEmote().getName())
{
case LEFT: if(newPageNum>1) newPageNum--; break;
case RIGHT: if(newPageNum<pages) newPageNum++; break;
case STOP: finalAction.accept(message); return;
}
try{event.getReaction().removeReaction(event.getUser()).queue();}catch(PermissionException e){}
int n = newPageNum;
message.editMessage(renderPage(newPageNum)).queue(m -> {
pagination(m, n);
});
}, timeout, unit, () -> finalAction.accept(message));
}
开发者ID:JDA-Applications,项目名称:JDA-Utilities,代码行数:26,代码来源:Paginator.java
示例19: queueMessage
import net.dv8tion.jda.core.exceptions.PermissionException; //导入依赖的package包/类
/**
* Send the given message to the given channel, optionally doing something with the message via the given consumer
* @param channel The channel to send the message to
* @param message The message to send to the channel
* @param consumer The consumer to handle the message
*/
public static void queueMessage(TextChannel channel, Message message, Consumer<Message> consumer) {
if (channel == null) {
DiscordSRV.debug("Tried sending a message to a null channel");
return;
}
try {
channel.sendMessage(message).queue(sentMessage -> {
DiscordSRV.api.callEvent(new DiscordGuildMessageSentEvent(getJda(), sentMessage));
if (consumer != null) consumer.accept(sentMessage);
if (DiscordSRV.getPlugin().getConsoleChannel() != null && !channel.getId().equals(DiscordSRV.getPlugin().getConsoleChannel().getId()))
DiscordSRV.getPlugin().getMetrics().increment("messages_sent_to_discord");
});
} catch (PermissionException e) {
if (e.getPermission() != Permission.UNKNOWN) {
DiscordSRV.warning("Could not send message in channel " + channel + " because the bot does not have the \"" + e.getPermission().getName() + "\" permission");
} else {
DiscordSRV.warning("Could not send message in channel " + channel + " because \"" + e.getMessage() + "\"");
}
} catch (IllegalStateException ignored) {}
}
开发者ID:Scarsz,项目名称:DiscordSRV,代码行数:29,代码来源:DiscordUtil.java
示例20: setTextChannelTopic
import net.dv8tion.jda.core.exceptions.PermissionException; //导入依赖的package包/类
/**
* Set the topic message of the given channel
* @param channel The channel to set the topic of
* @param topic The new topic to be set
*/
public static void setTextChannelTopic(TextChannel channel, String topic) {
if (channel == null) {
DiscordSRV.debug("Attempted to set status of null channel");
return;
}
try {
channel.getManager().setTopic(topic).queue();
} catch (PermissionException e) {
if (e.getPermission() != Permission.UNKNOWN) {
DiscordSRV.warning("Could not set topic of channel " + channel + " because the bot does not have the \"" + e.getPermission().getName() + "\" permission");
} else {
DiscordSRV.warning("Could not set topic of channel " + channel + " because \"" + e.getMessage() + "\"");
}
} catch (IllegalStateException ignored) {}
}
开发者ID:Scarsz,项目名称:DiscordSRV,代码行数:22,代码来源:DiscordUtil.java
注:本文中的net.dv8tion.jda.core.exceptions.PermissionException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论