Building messages
DDBKitUtilities exposes a collection of utiltity builders for creating structured messages.
This makes it a lot easier to format your message text or create complex messages with embeds, components, and buttons.
This also makes it easier to use conditional logic in your messages to keep your code clean and readable.
Remember to import the module before using it with import DDBKitUtilities
.
DDBKitUtilities adds methods to your GatewayManager
(your bot instance) that wrap their respective DiscordClient
methods.
They accept Message
types instead of the normal payloads as Message
does the conversion under the hood.
You start off by instanciating a message with
This is an empty message, but you can’t send empty messages. Also it’ll error due to ambiguity with different ways of initialising it. You can take this two different ways:
- You can send purely text content
- You can make a full message with embeds and all that
Sending text content can be made easier with this convenience initialiser.
This is the equivalent of using the component-based normal initialiser:
You’ll need to use the normal initialiser to have anything else like embeds and components.
As you can tell, the MessageComponent
s you can use generally start with the Message prefix, keep that in mind.
The following components exist:
MessageContent
*MessageEmbed
MessageComponents
*MessageAttachment
MessagePoll
*MessageSticker
Items marked with
*
are singular, and only the last declared instance will be used if any.
MessageContent
This is the main content of the message, and either this or an embed is required in a message to be sent.
The following MessageContentComponent
types exist:
Text
URL
Heading
Blockquote
Code
Codeblock
OrderedList
UnorderedList
We’ll go through the usage of each one.
Text
The most basic component, just text
. It also has many modifiers to change it’s style.
You can chain these modifiers together if you’d like.
Sometimes, you may need to have many Text
components on a single line sometimes, so use the grouped convenience initialiser.
URL
URLs are just Text
components with a URL inside them. This component lets you conveniently mask links or disable embeds (link previews).
Heading
Headings are single line, hence only one Text
component is allowed.
Or use the Text
component convenience initialiser.
Blockquote
Blockquotes can accept all MessageContentComponent
types, though I wouldn’t recommend using another Blockquote
in it.
Code
Code is the inline form of codeblocks, and just takes a String
type.
Codeblock
Codeblocks are cool, and can have a language specified.
OrderedList
and UnorderedList
OrderedList can accept Text
and UnorderedList
components.
And you can put lists inside lists.
MessageEmbed
Embeds are cool, and can have a lot of stuff in them in a nice, formatted manner.
The following MessageEmbedComponent
types exist:
Title
Description
Image
Thumbnail
Video
Field
Footer
The MessageEmbed
component also has modifiers, which include:
func setKind(_ kind: Embed.Kind)
func setTimestamp(_ date: Date = .now)
func setColor(_ color: DiscordColor?)
func setURL(_ url: String)
func setProvider(_ name: String, url: String? = nil)
func setAuthor(_ name: String, url: String? = nil, icon_url: Embed.DynamicURL? = nil)
MessageEmbed - Components
Title
The title of the embed, which is a single line String
type.