public class MessageBuilder
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
MessageBuilder.Formatting
Holds the Available formatting used in
appendString(String, net.dv8tion.jda.core.MessageBuilder.Formatting...) |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
EVERYONE_KEY |
static java.lang.String |
HERE_KEY |
static java.lang.String |
ROLE_KEY |
static java.lang.String |
TEXTCHANNEL_KEY |
static java.lang.String |
USER_KEY |
Constructor and Description |
---|
MessageBuilder() |
Modifier and Type | Method and Description |
---|---|
MessageBuilder |
appendCodeBlock(java.lang.String text,
java.lang.String language)
Appends a code-block to the Message
|
MessageBuilder |
appendEveryoneMention()
Appends a @everyone mention to the Message
|
MessageBuilder |
appendFormat(java.lang.String format,
java.lang.Object... args)
This method is an extended form of
String.format(String, Object...) . |
MessageBuilder |
appendHereMention()
Appends a @here mention to the Message
|
MessageBuilder |
appendMention(Role role)
Appends a Role mention to the Message.
|
MessageBuilder |
appendMention(TextChannel channel)
Appends a channel mention to the Message.
|
MessageBuilder |
appendMention(User user)
Appends a mention to the Message
|
MessageBuilder |
appendString(java.lang.String text)
Appends a string to the Message
|
MessageBuilder |
appendString(java.lang.String text,
MessageBuilder.Formatting... format)
Appends a formatted string to the Message
|
Message |
build()
Creates a
Message object from this Builder |
int |
getLength()
|
MessageBuilder |
setTTS(boolean tts)
Makes the created Message a TTS message
|
public static final java.lang.String USER_KEY
public static final java.lang.String ROLE_KEY
public static final java.lang.String TEXTCHANNEL_KEY
public static final java.lang.String EVERYONE_KEY
public static final java.lang.String HERE_KEY
public MessageBuilder setTTS(boolean tts)
tts
- whether the created Message should be a tts messagepublic MessageBuilder appendString(java.lang.String text)
text
- the text to appendpublic MessageBuilder appendString(java.lang.String text, MessageBuilder.Formatting... format)
text
- the text to appendformat
- the format(s) to apply to the textpublic MessageBuilder appendFormat(java.lang.String format, java.lang.Object... args)
String.format(String, Object...)
. It allows for all of
the token replacement functionality that String.format(String, Object...) supports, but it also supports
specialized token replacement specific to JDA objects.
Current tokens:
User
.
Same as appendMention(net.dv8tion.jda.core.entities.User)
Role
.
Same as appendMention(net.dv8tion.jda.core.entities.Role)
TextChannel
.
Same as appendMention(net.dv8tion.jda.core.entities.TextChannel)
appendEveryoneMention()
appendHereMention()
Example:
If you placed the following code in an method handling a
MessageReceivedEvent
User user = event.getAuthor();
MessageBuilder builder = new MessageBuilder();
builder.appendFormat("%U% is really cool!", user);
builder.build();
It would build a message that mentions the author and says that he is really cool!. If the user's
name was "Bob", it would say:"Bob is really cool!"
format
- A format string.args
- An array objects that will be used to replace the tokens.
They must be provided in the order that the tokens appear in the provided format string.public MessageBuilder appendCodeBlock(java.lang.String text, java.lang.String language)
text
- the code to appendlanguage
- the language of the code. If unknown use an empty stringpublic MessageBuilder appendMention(User user)
user
- the user to mentionpublic MessageBuilder appendEveryoneMention()
public MessageBuilder appendHereMention()
public MessageBuilder appendMention(TextChannel channel)
channel
- the TextChannel to mentionpublic MessageBuilder appendMention(Role role)
role
- the Role to mentionpublic int getLength()
Message
when build()
is called.0
or greater than 2000
when build()
is called, an exception
will be raised.public Message build()
Message
object from this BuilderMessage
java.lang.UnsupportedOperationException
-