Package tv.phantombot.discord.util
Class DiscordUtil
java.lang.Object
tv.phantombot.discord.util.DiscordUtil
- Direct Known Subclasses:
DiscordAPI
Has all of the methods to work with Discord4J.
- Author:
- IllusionaryOne, ScaniaTV
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addReaction
(Message message, ReactionEmoji emoji) Method that adds a reaction to a message.void
addReaction
(Message message, String emoji) Method that adds a reaction to a message.void
addReactions
(Message message, ReactionEmoji... emojis) Method that adds multiple reactions to a message.void
addReactions
(Message message, String... emojis) Method that adds a reaction to a message.void
Method to set a role on a user.void
Method to set a role on a user.void
Method to set a role on a user.void
bulkDelete
(GuildMessageChannel channel, int amount) Method to bulk delete messages from a channel.void
bulkDelete
(String channelName, int amount) Method to bulk delete messages from a channel.void
bulkDeleteMessages
(GuildMessageChannel channel, Message... list) Method to bulk delete messages from a channel.void
bulkDeleteMessages
(String channelName, Message... messages) Method to bulk delete messages from a channel.boolean
canChannelPublish
(GuildMessageChannel channel) * Indicates if the channel is a type that is allowed to publish crosspostsboolean
canChannelPublish
(String channelName) * Indicates if the channel is a type that is allowed to publish crosspostsstatic String
channelIdAsString
(Channel channel) static String
channelName
(Channel channel) void
createRole
(String roleName) Method to create a new role.void
deleteMessage
(Message message) Method to delete a message.void
deleteRole
(Role role) Method to delete a role.void
deleteRole
(String roleName) Method to delete a role.void
editMessageContent
(Message message, String newMessage) Method to edit message content.void
editMessageEmbed
(Message message, EmbedCreateSpec newEmbed) Method to edit message embeds.void
editUserRoles
(User user, Role... roles) Method to edit roles on a user, multiple can be set at once to replace the current ones.void
editUserRoles
(String userId, Role... roles) Method to edit roles on a user, multiple can be set at once to replace the current ones.getChannel
(String channelName) Method to return a channel object by its name.getChannelAsync
(String channelName) getChannelAsync
(String channelName, Predicate<? super GuildChannel> filter) getChannelByID
(String channelId) Method to return a channel object by its ID.getChannelByIDAsync
(String channelId) Method to get a color object.Method that gets a list of guild roles.getLastMessage
(String channelName) Method to return a the last message of a given channel.getMessageById
(String channelName, String messageId) Method to return a message by its id.getMessagesBefore
(String channelName, String messageId) Method to return a list of all messages before the given message.getRoleAsync
(String roleName) Method to return a role object by its name.getRoleByID
(String id) Method that returns a role by its ID.Role[]
getRoleObjects
(String... roles) Method to get an array of role objects by a string of role names.getRoleObjectsAsync
(String... roles) getRolesAsync
(String... roleNames) Search for Discord roles by display name or mention and return a Flux
Matching is performed case insensitively
The Flux is sorted so the roles are returned in permission order, as displayed in the Discord roles list of the Guild settings.getUserAsync
(String userName) Method to return a user object by its name.getUserById
(long userId) getUserByIdAsync
(long userId) Method to return a user object by its id.Role[]
getUserRoles
(User user) Method to get a list of a user's roles.Role[]
getUserRoles
(String userId) Method to get a list of a user's roles.getUserRolesAsync
(User user) getUserRolesAsync
(String userId) getUsers()
Method that gets all server membersgetUserWithDiscriminator
(String userName, String discriminator) Deprecated, for removal: This API element is subject to removal in a future version.Discriminators have been removed from DiscordgetUserWithDiscriminatorAsync
(String userName, String discriminator) Deprecated, for removal: This API element is subject to removal in a future version.Discriminators have been removed from Discordboolean
isAdministrator
(User user) Method to check if someone is an administrator.boolean
isAdministrator
(String userName) Method to check if someone is an administrator.isAdministratorAsync
(User user) isAdministratorAsync
(String userName) boolean
isValidFilePath
(String fileLocation) void
Method to remove the current game or reset the streaming status.void
removeRole
(Role role, User user) Method to remove a role on a user.void
removeRole
(String roleName, String userName) Method to remove a role on a user.void
sanitizeChannelName
(String channelName) Method that removes the # in the channel name.sendFile
(GuildMessageChannel channel, String fileLocation) Method to send a file to a channel.sendFile
(GuildMessageChannel channel, String message, String fileLocation) Method to send a file to a channel.Method to send a file to a channel.sendFileAsync
(GuildMessageChannel channel, String message, String fileLocation) sendFileAsync
(GuildMessageChannel channel, String message, DiscordUtil.MessageCreateFile file) sendFileAsync
(String channelName, String message, String fileLocation) sendMessage
(MessageChannel channel, String message) sendMessage
(String channelName, String message) Method to send a message to a channel.sendMessageAsync
(MessageChannel channel, String message) sendMessageAsync
(String channelName, String message) sendMessageEmbed
(GuildMessageChannel channel, EmbedCreateSpec embed) sendMessageEmbed
(GuildMessageChannel channel, String color, String message) Method to send embed messages.sendMessageEmbed
(String channelName, EmbedCreateSpec embed) Method to send embed messages.sendMessageEmbed
(String channelName, String color, String message) Method to send embed messages.sendMessageEmbedAsync
(GuildMessageChannel channel, EmbedCreateSpec embed) sendMessageEmbedAsync
(GuildMessageChannel channel, String color, String message) sendMessageEmbedAsync
(String channelName, EmbedCreateSpec embed) void
sendPrivateMessage
(PrivateChannel channel, String message) void
sendPrivateMessage
(User user, String message) Method to send private messages to a user.void
sendPrivateMessage
(String userName, String message) Method to send private messages to a user.void
setCompeting
(String competingIn) void
Method to set the current game.void
setListening
(String listeningTo) void
setPlaying
(String game) void
Method to set the current game and stream.void
setStreaming
(String streaming, String url) void
setWatching
(String watching)
-
Constructor Details
-
DiscordUtil
public DiscordUtil()
-
-
Method Details
-
sanitizeChannelName
Method that removes the # in the channel name.- Parameters:
channelName
-- Returns:
-
isValidFilePath
-
sendMessage
-
sendMessageAsync
-
sendMessage
Method to send a message to a channel.- Parameters:
channelName
-message
-- Returns:
-
sendMessageAsync
-
sendPrivateMessage
Method to send private messages to a user.- Parameters:
user
-message
-
-
sendPrivateMessage
Method to send private messages to a user.- Parameters:
userName
-message
-
-
sendPrivateMessage
-
sendMessageEmbed
-
sendMessageEmbedAsync
-
sendMessageEmbed
Method to send embed messages.- Parameters:
channelName
-embed
-- Returns:
-
sendMessageEmbedAsync
-
sendMessageEmbed
Method to send embed messages.- Parameters:
channel
-message
-color
-- Returns:
-
sendMessageEmbedAsync
public Mono<Message> sendMessageEmbedAsync(GuildMessageChannel channel, String color, String message) -
sendMessageEmbed
Method to send embed messages.- Parameters:
channelName
-message
-color
-- Returns:
-
sendFile
-
sendFileAsync
public Mono<Message> sendFileAsync(GuildMessageChannel channel, String message, String fileLocation) -
sendFileAsync
public Mono<Message> sendFileAsync(GuildMessageChannel channel, String message, DiscordUtil.MessageCreateFile file) -
sendFile
Method to send a file to a channel.- Parameters:
channelName
-message
-fileLocation
-- Returns:
-
sendFileAsync
-
sendFile
Method to send a file to a channel.- Parameters:
channel
-fileLocation
-- Returns:
-
sendFile
Method to send a file to a channel.- Parameters:
channelName
-fileLocation
-- Returns:
-
addReaction
Method that adds a reaction to a message.- Parameters:
message
- The message objectemoji
- The reaction object
-
addReactions
Method that adds multiple reactions to a message.- Parameters:
message
- The message objectemojis
- The reaction objects
-
addReaction
Method that adds a reaction to a message.- Parameters:
message
- The message objectemoji
- The emoji unicode
-
addReactions
Method that adds a reaction to a message.- Parameters:
message
- The message objectemojis
- The emoji unicodes
-
canChannelPublish
* Indicates if the channel is a type that is allowed to publish crossposts- Parameters:
channelName
- The channel to check- Returns:
-
canChannelPublish
* Indicates if the channel is a type that is allowed to publish crossposts- Parameters:
channel
- The channel to check- Returns:
-
getChannel
Method to return a channel object by its name.- Parameters:
channelName
- - The name of the channel.- Returns:
-
getChannelAsync
-
getChannelAsync
public Mono<GuildMessageChannel> getChannelAsync(String channelName, Predicate<? super GuildChannel> filter) -
getAllChannelInfo
-
getAllChannelInfoAsync
-
getChannelByID
Method to return a channel object by its ID.- Parameters:
channelId
- - The string ID of the channel- Returns:
-
getChannelByIDAsync
-
getUser
-
getUserAsync
Method to return a user object by its name.- Parameters:
userName
- - The user's name.- Returns:
-
getUserById
-
getUserByIdAsync
Method to return a user object by its id.- Parameters:
userId
- - The ID of the user.- Returns:
-
getUserWithDiscriminator
@Deprecated(since="3.10.0.0", forRemoval=true) public User getUserWithDiscriminator(String userName, String discriminator) Deprecated, for removal: This API element is subject to removal in a future version.Discriminators have been removed from Discord -
getUserWithDiscriminatorAsync
@Deprecated(since="3.10.0.0", forRemoval=true) public Mono<User> getUserWithDiscriminatorAsync(String userName, String discriminator) Deprecated, for removal: This API element is subject to removal in a future version.Discriminators have been removed from DiscordMethod to return a user object by its name and its discriminator.- Parameters:
userName
-discriminator
-- Returns:
-
getRolesAsync
Search for Discord roles by display name or mention and return a Flux
Matching is performed case insensitively
The Flux is sorted so the roles are returned in permission order, as displayed in the Discord roles list of the Guild settings. The sort starts with the cloest role to @everyone, and then continues up- Parameters:
roleNames
- The role names or mentions to find- Returns:
- a Flux containing matching roles
-
getRole
-
getRoleAsync
Method to return a role object by its name.- Parameters:
roleName
-- Returns:
-
getRoleByID
-
getRoleByIDAsync
Method that returns a role by its ID.- Parameters:
id
-- Returns:
-
getRoleObjects
Method to get an array of role objects by a string of role names.- Parameters:
roles
-- Returns:
-
getRoleObjectsAsync
-
getUserRoles
Method to get a list of a user's roles.- Parameters:
user
-- Returns:
-
getUserRolesAsync
-
getUserRoles
Method to get a list of a user's roles.- Parameters:
userId
-- Returns:
-
getUserRolesAsync
-
editUserRoles
Method to edit roles on a user, multiple can be set at once to replace the current ones.- Parameters:
user
-roles
-
-
editUserRoles
Method to edit roles on a user, multiple can be set at once to replace the current ones.- Parameters:
userId
-roles
-
-
addRole
Method to set a role on a user.- Parameters:
role
-user
-
-
addRole
Method to set a role on a user.- Parameters:
roleName
-userName
-
-
addRole
Method to set a role on a user.- Parameters:
roleName
-user
-
-
removeRole
Method to remove a role on a user.- Parameters:
role
-user
-
-
removeRole
Method to remove a role on a user.- Parameters:
roleName
-userName
-
-
createRole
Method to create a new role.- Parameters:
roleName
-
-
deleteRole
Method to delete a role.- Parameters:
role
-
-
deleteRole
Method to delete a role.- Parameters:
roleName
-
-
getGuildRoles
Method that gets a list of guild roles.- Returns:
-
getGuildRolesAsync
-
isAdministrator
Method to check if someone is an administrator.- Parameters:
user
-- Returns:
-
isAdministratorAsync
-
isAdministrator
Method to check if someone is an administrator.- Parameters:
userName
-- Returns:
-
isAdministratorAsync
-
bulkDelete
Method to bulk delete messages from a channel.- Parameters:
channel
-amount
-
-
bulkDelete
Method to bulk delete messages from a channel.- Parameters:
channelName
-amount
-
-
bulkDeleteMessages
Method to bulk delete messages from a channel.- Parameters:
channel
-list
-
-
bulkDeleteMessages
Method to bulk delete messages from a channel.- Parameters:
channelName
-messages
-
-
deleteMessage
Method to delete a message.- Parameters:
message
-
-
setCompeting
-
setListening
-
setWatching
-
setPlaying
-
setStreaming
-
resetPresence
public void resetPresence() -
setGame
Method to set the current game.- Parameters:
game
-
-
setStream
Method to set the current game and stream.- Parameters:
game
-url
-
-
removeGame
public void removeGame()Method to remove the current game or reset the streaming status. -
getUsers
Method that gets all server members- Returns:
-
getUsersAsync
-
getColor
Method to get a color object.- Parameters:
color
-- Returns:
-
getMessageById
Method to return a message by its id.- Parameters:
channelName
-messageId
-- Returns:
-
editMessageContent
Method to edit message content.- Parameters:
message
-newMessage
-
-
editMessageEmbed
Method to edit message embeds.- Parameters:
message
-newEmbed
-
-
getMessagesBefore
Method to return a list of all messages before the given message.- Parameters:
channelName
-messageId
-- Returns:
-
getLastMessage
Method to return a the last message of a given channel.- Parameters:
channelName
-- Returns:
-
channelId
-
channelIdAsString
-
channelName
-