当前位置: 首页>>代码示例>>Java>>正文


Java PermissionException.getPermission方法代码示例

本文整理汇总了Java中net.dv8tion.jda.core.exceptions.PermissionException.getPermission方法的典型用法代码示例。如果您正苦于以下问题:Java PermissionException.getPermission方法的具体用法?Java PermissionException.getPermission怎么用?Java PermissionException.getPermission使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.dv8tion.jda.core.exceptions.PermissionException的用法示例。


在下文中一共展示了PermissionException.getPermission方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: addRolesToMember

import net.dv8tion.jda.core.exceptions.PermissionException; //导入方法依赖的package包/类
public static void addRolesToMember(Member member, Role... roles) {
    List<Role> rolesToAdd = Arrays.stream(roles)
            .filter(role -> !role.isManaged())
            .filter(role -> !role.getGuild().getPublicRole().getId().equals(role.getId()))
            .collect(Collectors.toList());

    try {
        member.getGuild().getController().addRolesToMember(member, rolesToAdd).queue();
    } catch (PermissionException e) {
        if (e.getPermission() != Permission.UNKNOWN) {
            DiscordSRV.warning("Could not promote " + member + " to role(s) " + rolesToAdd + " because the bot does not have the \"" + e.getPermission().getName() + "\" permission");
        } else {
            DiscordSRV.warning("Could not promote " + member + " to role(s) " + rolesToAdd + " because \"" + e.getMessage() + "\"");
        }
    }
}
 
开发者ID:Scarsz,项目名称:DiscordSRV,代码行数:17,代码来源:DiscordUtil.java

示例5: removeRolesFromMember

import net.dv8tion.jda.core.exceptions.PermissionException; //导入方法依赖的package包/类
public static void removeRolesFromMember(Member member, Role... roles) {
    List<Role> rolesToRemove = Arrays.stream(roles)
            .filter(role -> !role.isManaged())
            .filter(role -> !role.getGuild().getPublicRole().getId().equals(role.getId()))
            .collect(Collectors.toList());

    try {
        member.getGuild().getController().removeRolesFromMember(member, rolesToRemove).queue();
    } catch (PermissionException e) {
        if (e.getPermission() != Permission.UNKNOWN) {
            DiscordSRV.warning("Could not demote " + member + " from role(s) " + rolesToRemove + " because the bot does not have the \"" + e.getPermission().getName() + "\" permission");
        } else {
            DiscordSRV.warning("Could not demote " + member + " from role(s) " + rolesToRemove + " because \"" + e.getMessage() + "\"");
        }
    }
}
 
开发者ID:Scarsz,项目名称:DiscordSRV,代码行数:17,代码来源:DiscordUtil.java

示例6: banMember

import net.dv8tion.jda.core.exceptions.PermissionException; //导入方法依赖的package包/类
public static void banMember(Member member, int daysOfMessagesToDelete) {
    if (member == null) {
        DiscordSRV.debug("Attempted to ban null member");
        return;
    }

    daysOfMessagesToDelete = Math.abs(daysOfMessagesToDelete);

    try {
        member.getGuild().getController().ban(member, daysOfMessagesToDelete).queue();
    } catch (PermissionException e) {
        if (e.getPermission() != Permission.UNKNOWN) {
            DiscordSRV.warning("Failed to ban " + member + " because the bot does not have the \"" + e.getPermission().getName() + "\" permission");
        } else {
            DiscordSRV.warning("Failed to ban " + member + " because \"" + e.getMessage() + "\"");
        }
    }
}
 
开发者ID:Scarsz,项目名称:DiscordSRV,代码行数:19,代码来源:DiscordUtil.java

示例7: sendImage

import net.dv8tion.jda.core.exceptions.PermissionException; //导入方法依赖的package包/类
/**
 * Sends an image with the embed
 *
 * @param builder
 * @param image
 * @param name
 * @param channel
 */
public static void sendImage(EmbedBuilder builder, byte[] image, String name, TextChannel channel) {
    try {
        channel.sendFile(image, name, new MessageBuilder().setEmbed(builder.build()).build()).queue();
    } catch (PermissionException e) {
        //we can't do anything about it
        if (e.getPermission() == Permission.MESSAGE_EMBED_LINKS) {
            channel.sendMessage("Lacking permission to embed links!").queue();
        }
    }
}
 
开发者ID:CyR1en,项目名称:Minecordbot,代码行数:19,代码来源:MessageUtils.java

示例8: sendMessageBlocking

import net.dv8tion.jda.core.exceptions.PermissionException; //导入方法依赖的package包/类
/**
 * Send the given message to the given channel, blocking the thread's execution until it's successfully sent then returning it
 * @param channel The channel to send the message to
 * @param message The message to send to the channel
 * @return The sent message
 */
public static Message sendMessageBlocking(TextChannel channel, Message message) {
    if (channel == null) {
        DiscordSRV.debug("Tried sending a message to a null channel");
        return null;
    }

    if (message == null || StringUtils.isBlank(message.getRawContent())) {
        DiscordSRV.debug("Tried sending a null or blank message");
        return null;
    }

    Message sentMessage;
    try {
        sentMessage = channel.sendMessage(message).complete();
    } 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() + "\"");
        }
        return null;
    }
    DiscordSRV.api.callEvent(new DiscordGuildMessageSentEvent(getJda(), sentMessage));

    if (DiscordSRV.getPlugin().getConsoleChannel() != null && !channel.getId().equals(DiscordSRV.getPlugin().getConsoleChannel().getId()))
        DiscordSRV.getPlugin().getMetrics().increment("messages_sent_to_discord");

    return sentMessage;
}
 
开发者ID:Scarsz,项目名称:DiscordSRV,代码行数:36,代码来源:DiscordUtil.java

示例9: deleteMessage

import net.dv8tion.jda.core.exceptions.PermissionException; //导入方法依赖的package包/类
/**
 * Delete the given message, given the bot has permission to
 * @param message The message to delete
 */
public static void deleteMessage(Message message) {
    if (message.isFromType(ChannelType.PRIVATE)) return;

    try {
        message.delete().queue();
    } catch (PermissionException e) {
        if (e.getPermission() != Permission.UNKNOWN) {
            DiscordSRV.warning("Could not delete message in channel " + message.getTextChannel() + " because the bot does not have the \"" + e.getPermission().getName() + "\" permission");
        } else {
            DiscordSRV.warning("Could not delete message in channel " + message.getTextChannel() + " because \"" + e.getMessage() + "\"");
        }
    }
}
 
开发者ID:Scarsz,项目名称:DiscordSRV,代码行数:18,代码来源:DiscordUtil.java

示例10: setNickname

import net.dv8tion.jda.core.exceptions.PermissionException; //导入方法依赖的package包/类
public static void setNickname(Member member, String nickname) {
    try {
        member.getGuild().getController().setNickname(member, nickname).queue();
    } catch (PermissionException e) {
        if (e.getPermission() != Permission.UNKNOWN) {
            DiscordSRV.warning("Could not set nickname for " + member + " because the bot does not have the \"" + e.getPermission().getName() + "\" permission");
        } else {
            DiscordSRV.warning("Could not set nickname for " + member + " because \"" + e.getMessage() + "\"");
        }
    }
}
 
开发者ID:Scarsz,项目名称:DiscordSRV,代码行数:12,代码来源:DiscordUtil.java


注:本文中的net.dv8tion.jda.core.exceptions.PermissionException.getPermission方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。