Java Code Examples for net.dv8tion.jda.api.Permission#UNKNOWN
The following examples show how to use
net.dv8tion.jda.api.Permission#UNKNOWN .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DiscordUtil.java From DiscordSRV with GNU General Public License v3.0 | 6 votes |
/** * 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 (Exception e) { if (e instanceof PermissionException) { PermissionException pe = (PermissionException) e; if (pe.getPermission() != Permission.UNKNOWN) { DiscordSRV.warning("Could not set topic of channel " + channel + " because the bot does not have the \"" + pe.getPermission().getName() + "\" permission"); } } else { DiscordSRV.warning("Could not set topic of channel " + channel + " because \"" + e.getMessage() + "\""); } } }
Example 2
Source File: DiscordUtil.java From DiscordSRV with GNU General Public License v3.0 | 6 votes |
public static void addRoleToMember(Member member, Role role) { if (member == null) { DiscordSRV.debug("Can't add role to null member"); return; } try { member.getGuild().addRoleToMember(member, role).queue(); } catch (PermissionException e) { if (e.getPermission() != Permission.UNKNOWN) { DiscordSRV.warning("Could not add " + member + " to role " + role + " because the bot does not have the \"" + e.getPermission().getName() + "\" permission"); } else { DiscordSRV.warning("Could not add " + member + " to role " + role + " because \"" + e.getMessage() + "\""); } } }
Example 3
Source File: DiscordUtil.java From DiscordSRV with GNU General Public License v3.0 | 6 votes |
public static void addRolesToMember(Member member, Role... roles) { if (member == null) { DiscordSRV.debug("Can't add roles to null member"); return; } 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().modifyMemberRoles(member, rolesToAdd, Collections.emptySet()).queue(); } catch (PermissionException e) { if (e.getPermission() != Permission.UNKNOWN) { DiscordSRV.warning("Could not add " + member + " to role(s) " + rolesToAdd + " because the bot does not have the \"" + e.getPermission().getName() + "\" permission"); } else { DiscordSRV.warning("Could not add " + member + " to role(s) " + rolesToAdd + " because \"" + e.getMessage() + "\""); } } }
Example 4
Source File: DiscordUtil.java From DiscordSRV with GNU General Public License v3.0 | 6 votes |
public static void removeRolesFromMember(Member member, Role... roles) { if (member == null) { DiscordSRV.debug("Can't remove roles from null member"); return; } 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().modifyMemberRoles(member, Collections.emptySet(), 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() + "\""); } } }
Example 5
Source File: DiscordUtil.java From DiscordSRV with GNU General Public License v3.0 | 6 votes |
public static void setNickname(Member member, String nickname) { if (member == null) { DiscordSRV.debug("Can't set nickname of null member"); return; } if (!member.getGuild().getSelfMember().canInteract(member)) { DiscordSRV.debug("Not setting " + member + "'s nickname because we can't interact with them"); return; } if (nickname != null && nickname.equals(member.getNickname())) { DiscordSRV.debug("Not setting " + member + "'s nickname because it wouldn't change"); return; } try { member.modifyNickname(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() + "\""); } } }
Example 6
Source File: DiscordUtil.java From DiscordSRV with GNU General Public License v3.0 | 6 votes |
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.ban(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() + "\""); } } }
Example 7
Source File: DiscordUtil.java From DiscordSRV with GNU General Public License v3.0 | 5 votes |
/** * 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 (getJda() == null) { DiscordSRV.debug("Tried sending a message when JDA was null"); return null; } if (channel == null) { DiscordSRV.debug("Tried sending a message to a null channel"); return null; } if (message == null || StringUtils.isBlank(message.getContentRaw())) { 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)); return sentMessage; }
Example 8
Source File: DiscordUtil.java From DiscordSRV with GNU General Public License v3.0 | 5 votes |
/** * 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() + "\""); } } }
Example 9
Source File: PermissionException.java From JDA with Apache License 2.0 | 2 votes |
/** * Creates a new PermissionException instance * * @param reason * The reason for this Exception */ public PermissionException(String reason) { this(Permission.UNKNOWN, reason); }