Using the MessageBuilder

The MessageBuilder class is a more powerful alternative to the TextChannel#sendMessage(...) method.

It can be used to construct more complex messages and supports some additional features that are not possible with a simple TextChannel#sendMessage(...) call.

🕵️‍♀️ Example

The following code

new MessageBuilder()
    .append("Look at these ")
    .append("awesome", MessageDecoration.BOLD, MessageDecoration.UNDERLINE)
    .append(" animal pictures! 😃")
    .appendCode("java", "System.out.println(\"Sweet!\");")
    .addAttachment(new File("C:/Users/Bastian/Pictures/kitten.jpg"))
    .addAttachment(new File("C:/Users/Bastian/Pictures/puppy.jpg"))
    .setEmbed(new EmbedBuilder()
            .setDescription("Really cool pictures!")

will be displayed like this:

📍 Allowed Mentions

The allowed mentions object lets you control what should be mentioned (pinged) in a message if it contains mentions.

The following code will ping:

  • The user0
  • All mentioned roles in the message

And will not ping:

  • @everyone and @here
  • The user1
AllowedMentions allowedMentions = new AllowedMentionsBuilder()

        new MessageBuilder()

If you add a user to the mentions object and set setMentionUsers(true) it will ping every mentioned user. The same applies for setMentionRoles(true)