Package dev.sympho.bot_utils
Class DiscordUtils
java.lang.Object
dev.sympho.bot_utils.DiscordUtils
Provides assorted utilities for interacting with Discord.
- Since:
- 1.0
- Version:
- 1.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classException that represents an error encountered while creating an attachment. -
Method Summary
Modifier and TypeMethodDescriptionstatic MessageCreateFields.FileattachData(String filename, byte[] data, boolean spoiler) Prepares data to be attached to a message as a file.static MessageCreateFields.FileattachImage(String name, BufferedImage image, boolean spoiler) Prepares an image to be attached to a message.static StringConstructs a mention to a channel.static StringmentionRole(Snowflake id) Constructs a mention to a role.static StringmentionUser(Snowflake id) Constructs a mention to a user.static <T> discord4j.discordjson.possible.Possible<T>toPossible(Optional<T> o) Converts anOptionalinto aPossible.static EmbedCreateSpecCreates an embed spec from an embed.
-
Method Details
-
toPossible
@SideEffectFree public static <T> discord4j.discordjson.possible.Possible<T> toPossible(Optional<T> o) Converts anOptionalinto aPossible.- Type Parameters:
T- The contained object type.- Parameters:
o- The optional.- Returns:
- The possible.
-
toSpec
Creates an embed spec from an embed.- Parameters:
embed- The embed.- Returns:
- The equivalent spec.
-
mentionUser
Constructs a mention to a user.- Parameters:
id- The ID of the user to mention.- Returns:
- The mention.
-
mentionRole
Constructs a mention to a role.- Parameters:
id- The ID of the role to mention.- Returns:
- The mention.
-
mentionChannel
Constructs a mention to a channel.- Parameters:
id- The ID of the channel to mention.- Returns:
- The mention.
-
attachData
@SideEffectFree public static MessageCreateFields.File attachData(String filename, byte[] data, boolean spoiler) throws DiscordUtils.AttachmentException Prepares data to be attached to a message as a file.- Parameters:
filename- The filename.data- The file data.spoiler- Whether to mark the file as a spoiler.- Returns:
- The prepared attachment.
- Throws:
DiscordUtils.AttachmentException- if an error occurs.
-
attachImage
@SideEffectFree public static MessageCreateFields.File attachImage(String name, BufferedImage image, boolean spoiler) throws DiscordUtils.AttachmentException Prepares an image to be attached to a message.- Parameters:
name- The image name (filename without extension).image- The image.spoiler- Whether to mark the image as a spoiler.- Returns:
- The prepared attachment.
- Throws:
DiscordUtils.AttachmentException- if an error occurs.
-