0
# Messaging System
1
2
Complete message handling including creation, editing, reactions, embeds, attachments, and rich message components for Discord communication.
3
4
## Capabilities
5
6
### Message Interface
7
8
Core message representation with content, metadata, and interaction capabilities.
9
10
```java { .api }
11
/**
12
* Represents a Message received from Discord.
13
* This contains all content and metadata of a Discord message.
14
*/
15
interface Message extends ISnowflake {
16
/** Get raw message content */
17
String getContentRaw();
18
19
/** Get formatted content for display */
20
String getContentDisplay();
21
22
/** Get content with all formatting stripped */
23
String getContentStripped();
24
25
/** Get message type */
26
MessageType getType();
27
28
/** Get message author */
29
User getAuthor();
30
31
/** Get author as guild member (null if not in guild) */
32
Member getMember();
33
34
/** Get channel where message was sent */
35
MessageChannel getChannel();
36
37
/** Get guild where message was sent (null if DM) */
38
Guild getGuild();
39
40
/** Get when message was sent */
41
OffsetDateTime getTimeCreated();
42
43
/** Get when message was last edited (null if never edited) */
44
OffsetDateTime getTimeEdited();
45
46
/** Check if message was edited */
47
boolean isEdited();
48
49
/** Check if message is pinned */
50
boolean isPinned();
51
52
/** Check if message is ephemeral (interaction response only) */
53
boolean isEphemeral();
54
55
/** Check if message is from webhook */
56
boolean isWebhookMessage();
57
58
/** Check if message is TTS */
59
boolean isTTS();
60
61
/** Check if message suppresses embeds */
62
boolean isSuppressedEmbeds();
63
64
/** Get message embeds */
65
List<MessageEmbed> getEmbeds();
66
67
/** Get message attachments */
68
List<Message.Attachment> getAttachments();
69
70
/** Get message components (buttons, select menus) */
71
List<ActionRow> getActionRows();
72
73
/** Get message reactions */
74
List<MessageReaction> getReactions();
75
76
/** Get message stickers */
77
List<StickerItem> getStickers();
78
79
/** Get message flags */
80
EnumSet<MessageFlag> getFlags();
81
82
/** Get referenced message (reply reference) */
83
Message getReferencedMessage();
84
MessageReference getMessageReference();
85
86
/** Get message activity (game invites, etc.) */
87
MessageActivity getActivity();
88
89
/** Get mentioned users */
90
List<User> getMentions();
91
List<User> getMentionedUsers();
92
93
/** Get mentioned channels */
94
List<TextChannel> getMentionedChannels();
95
96
/** Get mentioned roles */
97
List<Role> getMentionedRoles();
98
99
/** Get mentioned members */
100
List<Member> getMentionedMembers();
101
102
/** Check if mentions everyone */
103
boolean mentionsEveryone();
104
105
/** Check if user/role/channel is mentioned */
106
boolean isMentioned(IMentionable mentionable);
107
boolean isMentioned(IMentionable mentionable, Message.MentionType... types);
108
109
/** Delete message */
110
RestAction<Void> delete();
111
112
/** Edit message content */
113
MessageEditAction editMessage(CharSequence newContent);
114
MessageEditAction editMessage(MessageEmbed newEmbed);
115
MessageEditAction editMessage(MessageEditData data);
116
117
/** Edit message embeds */
118
MessageEditAction editMessageEmbeds(MessageEmbed... embeds);
119
MessageEditAction editMessageEmbeds(Collection<? extends MessageEmbed> embeds);
120
121
/** Edit message components */
122
MessageEditAction editMessageComponents(ActionRow... components);
123
MessageEditAction editMessageComponents(Collection<? extends ActionRow> components);
124
125
/** Edit message attachments */
126
MessageEditAction editMessageAttachments(AttachedFile... attachments);
127
MessageEditAction editMessageAttachments(Collection<? extends AttachedFile> attachments);
128
129
/** Pin message */
130
RestAction<Void> pin();
131
132
/** Unpin message */
133
RestAction<Void> unpin();
134
135
/** Add reaction */
136
RestAction<Void> addReaction(Emoji emoji);
137
138
/** Remove reaction */
139
RestAction<Void> removeReaction(Emoji emoji);
140
RestAction<Void> removeReaction(Emoji emoji, User user);
141
142
/** Clear all reactions */
143
RestAction<Void> clearReactions();
144
145
/** Clear reactions for specific emoji */
146
RestAction<Void> clearReactions(Emoji emoji);
147
148
/** Retrieve users who reacted with emoji */
149
ReactionPaginationAction retrieveReactionUsers(Emoji emoji);
150
151
/** Crosspost message (announcement channels) */
152
RestAction<Message> crosspost();
153
154
/** Suppress embeds */
155
RestAction<Message> suppressEmbeds(boolean suppressed);
156
157
/** Create thread from message */
158
ThreadChannelAction createThreadChannel(String name);
159
160
/** Reply to message */
161
MessageCreateAction reply(CharSequence text);
162
MessageCreateAction reply(MessageEmbed embed);
163
MessageCreateAction reply(MessageCreateData message);
164
165
/** Reply with embeds */
166
MessageCreateAction replyEmbeds(MessageEmbed... embeds);
167
MessageCreateAction replyEmbeds(Collection<? extends MessageEmbed> embeds);
168
169
/** Reply with files */
170
MessageCreateAction replyFiles(FileUpload... files);
171
MessageCreateAction replyFiles(Collection<? extends FileUpload> files);
172
}
173
```
174
175
### Message Creation
176
177
Fluent interface for creating and sending new messages with all supported content types.
178
179
```java { .api }
180
/**
181
* Extension of RestAction for creating messages with additional message-specific methods.
182
*/
183
interface MessageCreateAction extends RestAction<Message> {
184
/** Set message content */
185
MessageCreateAction setContent(String content);
186
187
/** Set message embeds */
188
MessageCreateAction setEmbeds(MessageEmbed... embeds);
189
MessageCreateAction setEmbeds(Collection<? extends MessageEmbed> embeds);
190
191
/** Add message embed */
192
MessageCreateAction addEmbeds(MessageEmbed... embeds);
193
MessageCreateAction addEmbeds(Collection<? extends MessageEmbed> embeds);
194
195
/** Set message components */
196
MessageCreateAction setComponents(ActionRow... components);
197
MessageCreateAction setComponents(Collection<? extends ActionRow> components);
198
199
/** Add message components */
200
MessageCreateAction addComponents(ActionRow... components);
201
MessageCreateAction addComponents(Collection<? extends ActionRow> components);
202
203
/** Set file attachments */
204
MessageCreateAction setFiles(FileUpload... files);
205
MessageCreateAction setFiles(Collection<? extends FileUpload> files);
206
207
/** Add file attachments */
208
MessageCreateAction addFiles(FileUpload... files);
209
MessageCreateAction addFiles(Collection<? extends FileUpload> files);
210
211
/** Set TTS (Text-to-Speech) */
212
MessageCreateAction setTTS(boolean tts);
213
214
/** Set whether to suppress embeds */
215
MessageCreateAction setSuppressEmbeds(boolean suppress);
216
217
/** Set allowed mentions */
218
MessageCreateAction setAllowedMentions(Collection<Message.MentionType> allowedMentions);
219
220
/** Mention users */
221
MessageCreateAction mentionUsers(long... userIds);
222
MessageCreateAction mentionUsers(String... userIds);
223
MessageCreateAction mentionUsers(User... users);
224
225
/** Mention roles */
226
MessageCreateAction mentionRoles(long... roleIds);
227
MessageCreateAction mentionRoles(String... roleIds);
228
MessageCreateAction mentionRoles(Role... roles);
229
230
/** Set message reference (reply) */
231
MessageCreateAction setMessageReference(Message message);
232
MessageCreateAction setMessageReference(long messageId);
233
MessageCreateAction setMessageReference(String messageId);
234
}
235
```
236
237
**Usage Examples:**
238
239
```java
240
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
241
import net.dv8tion.jda.api.utils.FileUpload;
242
243
// Basic text message
244
channel.sendMessage("Hello, World!").queue();
245
246
// Message with embed
247
EmbedBuilder embed = new EmbedBuilder()
248
.setTitle("Welcome!")
249
.setDescription("Thanks for joining our server")
250
.setColor(Color.BLUE);
251
channel.sendMessage("").setEmbeds(embed.build()).queue();
252
253
// Message with file
254
FileUpload file = FileUpload.fromData(imageBytes, "image.png");
255
channel.sendMessage("Check out this image!").setFiles(file).queue();
256
257
// Message with components
258
Button button = Button.primary("help", "Get Help");
259
channel.sendMessage("Need assistance?")
260
.setComponents(ActionRow.of(button))
261
.queue();
262
263
// Reply to message
264
originalMessage.reply("I'm replying to you!").queue();
265
266
// Complex message with everything
267
channel.sendMessage("Complex message")
268
.setEmbeds(embed.build())
269
.setFiles(file)
270
.setComponents(ActionRow.of(button))
271
.setTTS(false)
272
.mentionUsers(user.getId())
273
.queue(
274
success -> System.out.println("Message sent!"),
275
error -> System.err.println("Failed to send: " + error.getMessage())
276
);
277
```
278
279
### Message Editing
280
281
Interface for modifying existing messages including content, embeds, and components.
282
283
```java { .api }
284
/**
285
* Extension of RestAction for editing messages.
286
*/
287
interface MessageEditAction extends RestAction<Message> {
288
/** Set new message content */
289
MessageEditAction setContent(String content);
290
291
/** Set new message embeds */
292
MessageEditAction setEmbeds(MessageEmbed... embeds);
293
MessageEditAction setEmbeds(Collection<? extends MessageEmbed> embeds);
294
295
/** Set new message components */
296
MessageEditAction setComponents(ActionRow... components);
297
MessageEditAction setComponents(Collection<? extends ActionRow> components);
298
299
/** Set new file attachments */
300
MessageEditAction setAttachments(AttachedFile... attachments);
301
MessageEditAction setAttachments(Collection<? extends AttachedFile> attachments);
302
303
/** Replace existing files */
304
MessageEditAction setFiles(FileUpload... files);
305
MessageEditAction setFiles(Collection<? extends FileUpload> files);
306
307
/** Set allowed mentions */
308
MessageEditAction setAllowedMentions(Collection<Message.MentionType> allowedMentions);
309
310
/** Mention users */
311
MessageEditAction mentionUsers(long... userIds);
312
MessageEditAction mentionUsers(String... userIds);
313
MessageEditAction mentionUsers(User... users);
314
315
/** Mention roles */
316
MessageEditAction mentionRoles(long... roleIds);
317
MessageEditAction mentionRoles(String... roleIds);
318
MessageEditAction mentionRoles(Role... roles);
319
320
/** Set whether to suppress embeds */
321
MessageEditAction setSuppressEmbeds(boolean suppress);
322
}
323
```
324
325
### Message Embeds
326
327
Rich embedded content with titles, descriptions, fields, images, and more.
328
329
```java { .api }
330
/**
331
* Builder for creating MessageEmbed objects.
332
*/
333
class EmbedBuilder {
334
/** Set embed title */
335
EmbedBuilder setTitle(String title);
336
EmbedBuilder setTitle(String title, String url);
337
338
/** Set embed description */
339
EmbedBuilder setDescription(CharSequence description);
340
341
/** Append to description */
342
EmbedBuilder appendDescription(CharSequence description);
343
344
/** Set embed timestamp */
345
EmbedBuilder setTimestamp(TemporalAccessor temporal);
346
347
/** Set embed color */
348
EmbedBuilder setColor(Color color);
349
EmbedBuilder setColor(int color);
350
351
/** Set thumbnail image */
352
EmbedBuilder setThumbnail(String url);
353
354
/** Set main image */
355
EmbedBuilder setImage(String url);
356
357
/** Set author information */
358
EmbedBuilder setAuthor(String name);
359
EmbedBuilder setAuthor(String name, String url);
360
EmbedBuilder setAuthor(String name, String url, String iconUrl);
361
362
/** Set footer information */
363
EmbedBuilder setFooter(String text);
364
EmbedBuilder setFooter(String text, String iconUrl);
365
366
/** Add field */
367
EmbedBuilder addField(String name, String value, boolean inline);
368
EmbedBuilder addField(MessageEmbed.Field field);
369
370
/** Add blank field */
371
EmbedBuilder addBlankField(boolean inline);
372
373
/** Clear all fields */
374
EmbedBuilder clearFields();
375
376
/** Get current field count */
377
int getFields();
378
379
/** Check if embed is empty */
380
boolean isEmpty();
381
382
/** Get total character count */
383
int length();
384
385
/** Build the embed */
386
MessageEmbed build();
387
}
388
389
/**
390
* Represents an embedded rich content object.
391
*/
392
interface MessageEmbed {
393
/** Get embed URL */
394
String getUrl();
395
396
/** Get embed title */
397
String getTitle();
398
399
/** Get embed description */
400
String getDescription();
401
402
/** Get embed type */
403
EmbedType getType();
404
405
/** Get embed timestamp */
406
OffsetDateTime getTimestamp();
407
408
/** Get embed color */
409
Color getColor();
410
int getColorRaw();
411
412
/** Get thumbnail */
413
MessageEmbed.Thumbnail getThumbnail();
414
415
/** Get site provider */
416
MessageEmbed.Provider getSiteProvider();
417
418
/** Get author info */
419
MessageEmbed.AuthorInfo getAuthor();
420
421
/** Get video info */
422
MessageEmbed.VideoInfo getVideoInfo();
423
424
/** Get footer */
425
MessageEmbed.Footer getFooter();
426
427
/** Get image info */
428
MessageEmbed.ImageInfo getImage();
429
430
/** Get fields */
431
List<MessageEmbed.Field> getFields();
432
433
/** Check if embed is empty */
434
boolean isEmpty();
435
436
/** Get total character count */
437
int getLength();
438
}
439
```
440
441
**Usage Examples:**
442
443
```java
444
import net.dv8tion.jda.api.EmbedBuilder;
445
import java.awt.Color;
446
import java.time.Instant;
447
448
// Simple embed
449
EmbedBuilder embed = new EmbedBuilder()
450
.setTitle("Server Statistics")
451
.setDescription("Current server information")
452
.addField("Members", "1,250", true)
453
.addField("Online", "420", true)
454
.addField("Channels", "45", true)
455
.setColor(Color.GREEN)
456
.setTimestamp(Instant.now())
457
.setFooter("Last updated");
458
459
channel.sendMessageEmbeds(embed.build()).queue();
460
461
// Complex embed with all features
462
EmbedBuilder complexEmbed = new EmbedBuilder()
463
.setTitle("User Profile", "https://example.com/profile")
464
.setAuthor("UserBot", null, "https://example.com/avatar.png")
465
.setDescription("Detailed user information and statistics")
466
.addField("Level", "42", true)
467
.addField("XP", "15,678", true)
468
.addField("Rank", "#127", true)
469
.addBlankField(false)
470
.addField("Recent Activity", "Last seen 2 hours ago", false)
471
.setThumbnail("https://example.com/user-avatar.png")
472
.setImage("https://example.com/user-banner.png")
473
.setColor(0x7289DA)
474
.setTimestamp(Instant.now())
475
.setFooter("Profile System", "https://example.com/bot-icon.png");
476
477
channel.sendMessageEmbeds(complexEmbed.build()).queue();
478
```
479
480
### Message Components
481
482
Interactive message components including buttons, select menus, and action rows.
483
484
```java { .api }
485
/**
486
* Represents a row of interactive components in a message.
487
*/
488
class ActionRow {
489
/** Create action row with components */
490
static ActionRow of(ItemComponent... components);
491
static ActionRow of(Collection<? extends ItemComponent> components);
492
493
/** Get components in this row */
494
List<ItemComponent> getComponents();
495
496
/** Check if row is empty */
497
boolean isEmpty();
498
}
499
500
/**
501
* Utility class for creating buttons.
502
*/
503
class Button {
504
/** Create primary button */
505
static Button primary(String id, String label);
506
static Button primary(String id, Emoji emoji);
507
static Button primary(String id, String label, Emoji emoji);
508
509
/** Create secondary button */
510
static Button secondary(String id, String label);
511
static Button secondary(String id, Emoji emoji);
512
static Button secondary(String id, String label, Emoji emoji);
513
514
/** Create success button */
515
static Button success(String id, String label);
516
static Button success(String id, Emoji emoji);
517
static Button success(String id, String label, Emoji emoji);
518
519
/** Create danger button */
520
static Button danger(String id, String label);
521
static Button danger(String id, Emoji emoji);
522
static Button danger(String id, String label, Emoji emoji);
523
524
/** Create link button */
525
static Button link(String url, String label);
526
static Button link(String url, Emoji emoji);
527
static Button link(String url, String label, Emoji emoji);
528
529
/** Get button ID */
530
String getId();
531
532
/** Get button label */
533
String getLabel();
534
535
/** Get button style */
536
ButtonStyle getStyle();
537
538
/** Get button emoji */
539
Emoji getEmoji();
540
541
/** Get button URL (link buttons only) */
542
String getUrl();
543
544
/** Check if button is disabled */
545
boolean isDisabled();
546
547
/** Create disabled version */
548
Button asDisabled();
549
550
/** Create enabled version */
551
Button asEnabled();
552
553
/** Modify button properties */
554
Button withId(String id);
555
Button withLabel(String label);
556
Button withEmoji(Emoji emoji);
557
Button withStyle(ButtonStyle style);
558
Button withUrl(String url);
559
Button withDisabled(boolean disabled);
560
}
561
562
/**
563
* Utility class for creating select menus.
564
*/
565
class SelectMenu {
566
/** Create string select menu */
567
static StringSelectMenu.Builder create(String customId);
568
569
/** Create entity select menu */
570
static EntitySelectMenu.Builder create(String customId, EntitySelectMenu.SelectTarget target);
571
}
572
```
573
574
**Usage Examples:**
575
576
```java
577
import net.dv8tion.jda.api.interactions.components.ActionRow;
578
import net.dv8tion.jda.api.interactions.components.buttons.Button;
579
import net.dv8tion.jda.api.interactions.components.selections.StringSelectMenu;
580
581
// Message with buttons
582
Button helpButton = Button.primary("help", "Get Help");
583
Button aboutButton = Button.secondary("about", "About");
584
Button websiteButton = Button.link("https://example.com", "Visit Website");
585
586
channel.sendMessage("Choose an option:")
587
.setComponents(ActionRow.of(helpButton, aboutButton, websiteButton))
588
.queue();
589
590
// Message with select menu
591
StringSelectMenu menu = StringSelectMenu.create("game-select")
592
.setPlaceholder("Choose a game")
593
.addOption("Minecraft", "minecraft", "Block building game")
594
.addOption("Fortnite", "fortnite", "Battle royale game")
595
.addOption("Among Us", "amongus", "Social deduction game")
596
.setMinValues(1)
597
.setMaxValues(1)
598
.build();
599
600
channel.sendMessage("What's your favorite game?")
601
.setComponents(ActionRow.of(menu))
602
.queue();
603
604
// Disabled button example
605
Button disabledButton = Button.danger("delete", "Delete").asDisabled();
606
channel.sendMessage("This action is currently unavailable")
607
.setComponents(ActionRow.of(disabledButton))
608
.queue();
609
```
610
611
### File Attachments
612
613
File upload and attachment handling for messages.
614
615
```java { .api }
616
/**
617
* Utility class for creating file uploads.
618
*/
619
class FileUpload {
620
/** Create from byte array */
621
static FileUpload fromData(byte[] data, String name);
622
623
/** Create from InputStream */
624
static FileUpload fromInputStream(InputStream data, String name);
625
626
/** Create from File */
627
static FileUpload fromFile(File file);
628
static FileUpload fromFile(File file, String name);
629
630
/** Create from Path */
631
static FileUpload fromPath(Path path);
632
static FileUpload fromPath(Path path, String name);
633
634
/** Get file name */
635
String getName();
636
637
/** Get file description */
638
String getDescription();
639
640
/** Set file description */
641
FileUpload setDescription(String description);
642
643
/** Check if file is spoiler */
644
boolean isSpoiler();
645
646
/** Set spoiler status */
647
FileUpload setSpoiler(boolean spoiler);
648
649
/** Close and release resources */
650
void close();
651
}
652
653
/**
654
* Represents a file attachment in a message.
655
*/
656
interface Message.Attachment {
657
/** Get attachment ID */
658
long getIdLong();
659
String getId();
660
661
/** Get file name */
662
String getFileName();
663
664
/** Get file description */
665
String getDescription();
666
667
/** Get content type */
668
String getContentType();
669
670
/** Get file size in bytes */
671
int getSize();
672
673
/** Get attachment URL */
674
String getUrl();
675
676
/** Get proxy URL */
677
String getProxyUrl();
678
679
/** Check if attachment is image */
680
boolean isImage();
681
682
/** Check if attachment is video */
683
boolean isVideo();
684
685
/** Check if attachment is spoiler */
686
boolean isSpoiler();
687
688
/** Get image dimensions (if image) */
689
int getWidth();
690
int getHeight();
691
692
/** Download attachment */
693
RestAction<InputStream> getProxy();
694
CompletableFuture<InputStream> downloadAsInputStream();
695
CompletableFuture<byte[]> downloadAsByteArray();
696
CompletableFuture<File> downloadToFile(File file);
697
CompletableFuture<Path> downloadToPath(Path path);
698
}
699
```
700
701
## Types
702
703
```java { .api }
704
// Message types
705
enum MessageType {
706
DEFAULT, RECIPIENT_ADD, RECIPIENT_REMOVE, CALL, CHANNEL_NAME_CHANGE,
707
CHANNEL_ICON_CHANGE, CHANNEL_PINNED_MESSAGE, GUILD_MEMBER_JOIN,
708
USER_PREMIUM_GUILD_SUBSCRIPTION, USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1,
709
USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2, USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3,
710
CHANNEL_FOLLOW_ADD, GUILD_DISCOVERY_DISQUALIFIED, GUILD_DISCOVERY_REQUALIFIED,
711
GUILD_DISCOVERY_GRACE_PERIOD_INITIAL_WARNING, GUILD_DISCOVERY_GRACE_PERIOD_FINAL_WARNING,
712
THREAD_CREATED, REPLY, CHAT_INPUT_COMMAND, THREAD_STARTER_MESSAGE,
713
GUILD_INVITE_REMINDER, CONTEXT_MENU_COMMAND, AUTO_MODERATION_ACTION,
714
ROLE_SUBSCRIPTION_PURCHASE, INTERACTION_PREMIUM_UPSELL, STAGE_START, STAGE_END,
715
STAGE_SPEAKER, STAGE_RAISE_HAND, STAGE_TOPIC, GUILD_APPLICATION_PREMIUM_SUBSCRIPTION
716
}
717
718
// Message flags
719
enum MessageFlag {
720
CROSSPOSTED, IS_CROSSPOST, SUPPRESS_EMBEDS, SOURCE_MESSAGE_DELETED,
721
URGENT, HAS_THREAD, EPHEMERAL, LOADING, FAILED_TO_MENTION_SOME_ROLES_IN_THREAD,
722
SUPPRESS_NOTIFICATIONS, IS_VOICE_MESSAGE
723
}
724
725
// Mention types
726
enum MentionType {
727
USER, ROLE, CHANNEL, EVERYONE, HERE, SLASH_COMMAND
728
}
729
730
// Button styles
731
enum ButtonStyle {
732
PRIMARY, SECONDARY, SUCCESS, DANGER, LINK
733
}
734
735
// Embed types
736
enum EmbedType {
737
RICH, IMAGE, VIDEO, GIFV, ARTICLE, LINK, AUTO_MODERATION_MESSAGE
738
}
739
```