/
Message.java
2779 lines (2638 loc) · 123 KB
/
Message.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.dv8tion.jda.api.entities;
import net.dv8tion.jda.annotations.ForRemoval;
import net.dv8tion.jda.annotations.ReplaceWith;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.channel.Channel;
import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.entities.channel.attribute.IThreadContainer;
import net.dv8tion.jda.api.entities.channel.concrete.*;
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.entities.channel.unions.GuildMessageChannelUnion;
import net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion;
import net.dv8tion.jda.api.entities.emoji.CustomEmoji;
import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.entities.emoji.RichCustomEmoji;
import net.dv8tion.jda.api.entities.sticker.GuildSticker;
import net.dv8tion.jda.api.entities.sticker.Sticker;
import net.dv8tion.jda.api.entities.sticker.StickerItem;
import net.dv8tion.jda.api.entities.sticker.StickerSnowflake;
import net.dv8tion.jda.api.exceptions.HttpException;
import net.dv8tion.jda.api.exceptions.InsufficientPermissionException;
import net.dv8tion.jda.api.exceptions.MissingAccessException;
import net.dv8tion.jda.api.interactions.InteractionType;
import net.dv8tion.jda.api.interactions.components.ActionRow;
import net.dv8tion.jda.api.interactions.components.LayoutComponent;
import net.dv8tion.jda.api.interactions.components.buttons.Button;
import net.dv8tion.jda.api.requests.RestAction;
import net.dv8tion.jda.api.requests.restaction.AuditableRestAction;
import net.dv8tion.jda.api.requests.restaction.MessageCreateAction;
import net.dv8tion.jda.api.requests.restaction.MessageEditAction;
import net.dv8tion.jda.api.requests.restaction.ThreadChannelAction;
import net.dv8tion.jda.api.requests.restaction.pagination.ReactionPaginationAction;
import net.dv8tion.jda.api.utils.AttachedFile;
import net.dv8tion.jda.api.utils.AttachmentProxy;
import net.dv8tion.jda.api.utils.FileUpload;
import net.dv8tion.jda.api.utils.data.DataObject;
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
import net.dv8tion.jda.api.utils.messages.MessageEditData;
import net.dv8tion.jda.api.utils.messages.MessageRequest;
import net.dv8tion.jda.internal.JDAImpl;
import net.dv8tion.jda.internal.entities.ReceivedMessage;
import net.dv8tion.jda.internal.requests.FunctionalCallback;
import net.dv8tion.jda.internal.requests.Requester;
import net.dv8tion.jda.internal.utils.Checks;
import net.dv8tion.jda.internal.utils.IOUtil;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.*;
import java.time.OffsetDateTime;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
* Represents a Text message received from Discord.
* <br>This represents messages received from {@link net.dv8tion.jda.api.entities.channel.middleman.MessageChannel MessageChannels}.
*
* <p><b>This type is not updated. JDA does not keep track of changes to messages, it is advised to do this via events such
* as {@link net.dv8tion.jda.api.events.message.MessageUpdateEvent MessageUpdateEvent} and similar.</b>
*
* <p><b>Message Differences</b><br>
* There are 2 implementations of this interface in JDA.
* <ol>
* <li><b>Received Message</b>
* <br>Messages received through events or history query.
* These messages hold information of <b>existing</b> messages and
* can be modified or deleted.</li>
* <li><b>System Message</b>
* <br>Specification of <b>Received Messages</b> that are generated by Discord
* on certain events. Commonly this is used in groups or to indicate a pin within a MessageChannel.
* The different types can be found in the {@link net.dv8tion.jda.api.entities.MessageType MessageType} enum.</li>
* </ol>
*
* <p>When a feature is not available it will throw an {@link java.lang.UnsupportedOperationException UnsupportedOperationException}
* as per interface specifications.
* <br>Specific operations may have specified information available in the {@code throws} javadoc.
*
* <p><b>Formattable</b><br>
* This interface extends {@link java.util.Formattable Formattable} and can be used with a {@link java.util.Formatter Formatter}
* such as used by {@link String#format(String, Object...) String.format(String, Object...)}
* or {@link java.io.PrintStream#printf(String, Object...) PrintStream.printf(String, Object...)}.
*
* <p>This will use {@link #getContentDisplay()} rather than {@link Object#toString()}!
* <br>Supported Features:
* <ul>
* <li><b>Alternative</b>
* <br> - Using {@link #getContentRaw()}
* (Example: {@code %#s} - uses {@link #getContentDisplay()})</li>
*
* <li><b>Width/Left-Justification</b>
* <br> - Ensures the size of a format
* (Example: {@code %20s} - uses at minimum 20 chars;
* {@code %-10s} - uses left-justified padding)</li>
*
* <li><b>Precision</b>
* <br> - Cuts the content to the specified size
* (replacing last 3 chars with {@code ...}; Example: {@code %.20s})</li>
* </ul>
*
* <p>More information on formatting syntax can be found in the {@link java.util.Formatter format syntax documentation}!
*
* @see MessageChannel#getIterableHistory()
* @see MessageChannel#getHistory()
* @see MessageChannel#getHistoryAfter(String, int)
* @see MessageChannel#getHistoryBefore(String, int)
* @see MessageChannel#getHistoryAround(String, int)
* @see MessageChannel#getHistoryFromBeginning(int)
* @see MessageChannel#retrieveMessageById(String)
*
* @see MessageChannel#deleteMessageById(String)
* @see MessageChannel#editMessageById(String, CharSequence)
*/
public interface Message extends ISnowflake, Formattable
{
/** Template for {@link #getJumpUrl()}.*/
String JUMP_URL = "https://discord.com/channels/%s/%s/%s";
/**
* The maximum sendable file size (8 MiB)
*
* @see MessageRequest#setFiles(Collection)
*/
int MAX_FILE_SIZE = 8 << 20;
/**
* The maximum sendable file size for nitro (50 MiB)
*
* @see MessageRequest#setFiles(Collection)
*/
int MAX_FILE_SIZE_NITRO = 50 << 20;
/**
* The maximum amount of files sendable within a single message ({@value})
*
* @see MessageRequest#setFiles(Collection)
*/
int MAX_FILE_AMOUNT = 10;
/**
* The maximum amount of characters sendable in one message. ({@value})
* <br>This only applies to the raw content and not embeds!
*
* @see MessageRequest#setContent(String)
*/
int MAX_CONTENT_LENGTH = 2000;
/**
* The maximum amount of reactions that can be added to one message ({@value})
*
* @see Message#addReaction(Emoji)
*/
int MAX_REACTIONS = 20;
/**
* The maximum amount of Embeds that can be added to one message ({@value})
*
* @see MessageChannel#sendMessageEmbeds(Collection)
* @see MessageRequest#setEmbeds(Collection)
*/
int MAX_EMBED_COUNT = 10;
/**
* The maximum amount of {@link Sticker Stickers} that can be added to a message ({@value})
*
* @see GuildMessageChannel#sendStickers(StickerSnowflake...)
* @see MessageCreateAction#setStickers(StickerSnowflake...)
*/
int MAX_STICKER_COUNT = 3;
/**
* The maximum amount of {@link LayoutComponent LayoutComponents} that can be added to a message ({@value})
*/
int MAX_COMPONENT_COUNT = 5;
/**
* The maximum character length for a {@link #getNonce() nonce} ({@value})
*/
int MAX_NONCE_LENGTH = 25;
/**
* Pattern used to find instant invites in strings.
*
* <p>The only named group is at index 1 with the name {@code "code"}.
*
* @see #getInvites()
*/
Pattern INVITE_PATTERN = Pattern.compile(
"(?:https?://)?" + // Scheme
"(?:\\w+\\.)?" + // Subdomain
"discord(?:(?:app)?\\.com" + // Discord domain
"/invite|\\.gg)/(?<code>[a-z0-9-]+)" + // Path
"(?:\\?\\S*)?(?:#\\S*)?", // Useless query or URN appendix
Pattern.CASE_INSENSITIVE);
/**
* Pattern used to find {@link #getJumpUrl() Jump URLs} in strings.
*
* <p><b>Groups</b><br>
* <table>
* <caption style="display: none">Javadoc is stupid, this is not a required tag</caption>
* <tr>
* <th>Index</th>
* <th>Name</th>
* <th>Description</th>
* </tr>
* <tr>
* <td>0</td>
* <td>N/A</td>
* <td>The entire link</td>
* </tr>
* <tr>
* <td>1</td>
* <td>guild</td>
* <td>The ID of the target guild</td>
* </tr>
* <tr>
* <td>2</td>
* <td>channel</td>
* <td>The ID of the target channel</td>
* </tr>
* <tr>
* <td>3</td>
* <td>message</td>
* <td>The ID of the target message</td>
* </tr>
* </table>
* You can use the names with {@link java.util.regex.Matcher#group(String) Matcher.group(String)}
* and the index with {@link java.util.regex.Matcher#group(int) Matcher.group(int)}.
*
* @see #getJumpUrl()
*/
Pattern JUMP_URL_PATTERN = Pattern.compile(
"(?:https?://)?" + // Scheme
"(?:\\w+\\.)?" + // Subdomain
"discord(?:app)?\\.com" + // Discord domain
"/channels/(?<guild>\\d+)/(?<channel>\\d+)/(?<message>\\d+)" + // Path
"(?:\\?\\S*)?(?:#\\S*)?", // Useless query or URN appendix
Pattern.CASE_INSENSITIVE);
/**
* Suppresses the warning for missing the {@link net.dv8tion.jda.api.requests.GatewayIntent#MESSAGE_CONTENT MESSAGE_CONTENT} intent and using one of the dependent getters.
*/
static void suppressContentIntentWarning()
{
ReceivedMessage.didContentIntentWarning = true;
}
/**
* Returns the {@link MessageReference} for this Message. This will be null if this Message has no reference.
*
* <p>You can access all the information about a reference through this object.
* Additionally, you can retrieve the referenced Message if discord did not load it in time. This can be done with {@link MessageReference#resolve()}.
*
* @return The message reference, or null.
*/
@Nullable
MessageReference getMessageReference();
/**
* Referenced message.
*
* <p>This will have different meaning depending on the {@link #getType() type} of message.
* Usually, this is a {@link MessageType#INLINE_REPLY INLINE_REPLY} reference.
* This can be null even if the type is {@link MessageType#INLINE_REPLY INLINE_REPLY}, when the message it references doesn't exist or discord wasn't able to resolve it in time.
*
* <p>This differs from a {@link MessageReference}, which contains the raw IDs attached to the reference, and allows you to retrieve the referenced message
*
* @return The referenced message, or null
*
* @see #getMessageReference()
*/
@Nullable
default Message getReferencedMessage()
{
return getMessageReference() != null
? getMessageReference().getMessage()
: null;
}
/**
* The {@link Mentions} used in this message.
*
* <p>This includes {@link Member Members}, {@link net.dv8tion.jda.api.entities.channel.middleman.GuildChannel GuildChannels}, {@link Role Roles}, and {@link CustomEmoji CustomEmojis}.
* Can also be used to check if a message mentions {@code @everyone} or {@code @here}.
*
* <p><b>Example</b><br>
* {@code
* System.out.println("Message mentioned these users: " + message.getMentions().getUsers());
* System.out.println("Message used these custom emojis: " + message.getMentions().getCustomEmojis());
* }
*
* @return {@link Mentions} for this message.
*/
@Nonnull
Mentions getMentions();
/**
* Returns whether or not this Message has been edited before.
*
* @return True if this message has been edited.
*/
boolean isEdited();
/**
* Provides the {@link java.time.OffsetDateTime OffsetDateTime} defining when this Message was last
* edited. If this Message has not been edited ({@link #isEdited()} is {@code false}), then this method
* will return {@code null}.
*
* @return Time of the most recent edit, or {@code null} if the Message has never been edited.
*/
@Nullable
OffsetDateTime getTimeEdited();
/**
* The author of this Message
*
* @return Message author
*/
@Nonnull
User getAuthor();
/**
* Returns the author of this Message as a {@link net.dv8tion.jda.api.entities.Member member}.
* <br><b>This is only valid if the Message was actually sent in a GuildMessageChannel.</b> This will return {@code null}
* if the message was not sent in a GuildMessageChannel, or if the message was sent by a Webhook.
* <br>You can check the type of channel this message was sent from using {@link #isFromType(ChannelType)} or {@link #getChannelType()}.
*
* <p>Discord does not provide a member object for messages returned by {@link RestAction RestActions} of any kind.
* This will return null if the message was retrieved through {@link net.dv8tion.jda.api.entities.channel.middleman.MessageChannel#retrieveMessageById(long)} or similar means,
* unless the member is already cached.
*
* @return Message author, or {@code null} if the message was not sent in a GuildMessageChannel, or if the message was sent by a Webhook.
*
* @see #isWebhookMessage()
*/
@Nullable
Member getMember();
/**
* Returns the jump-to URL for the received message. Clicking this URL in the Discord client will cause the client to
* jump to the specified message.
*
* @return A String representing the jump-to URL for the message
*/
@Nonnull
String getJumpUrl();
/**
* The textual content of this message in the format that would be shown to the Discord client. All
* {@link net.dv8tion.jda.api.entities.IMentionable IMentionable} entities will be resolved to the format
* shown by the Discord client instead of the {@literal <id>} format.
*
* <p>This includes resolving:
* <br>{@link User Users} / {@link net.dv8tion.jda.api.entities.Member Members}
* to their @Username/@Nickname format,
* <br>{@link net.dv8tion.jda.api.entities.channel.middleman.GuildChannel GuildChannels} to their #ChannelName format,
* <br>{@link net.dv8tion.jda.api.entities.Role Roles} to their @RoleName format
* <br>{@link CustomEmoji Custom Emojis} (not unicode emojis!) to their {@code :name:} format.
*
* <p>If you want the actual Content (mentions as {@literal <@id>}), use {@link #getContentRaw()} instead
*
* <p><b>Requires {@link net.dv8tion.jda.api.requests.GatewayIntent#MESSAGE_CONTENT GatewayIntent.MESSAGE_CONTENT}</b>
*
* @return The textual content of the message with mentions resolved to be visually like the Discord client.
*/
@Nonnull
String getContentDisplay();
/**
* The raw textual content of this message. Does not resolve {@link net.dv8tion.jda.api.entities.IMentionable IMentionable}
* entities like {@link #getContentDisplay()} does. This means that this is the completely raw textual content of the message
* received from Discord and can contain mentions specified by
* <a href="https://discord.com/developers/docs/resources/channel#message-formatting" target="_blank">Discord's Message Formatting</a>.
*
* <p><b>Requires {@link net.dv8tion.jda.api.requests.GatewayIntent#MESSAGE_CONTENT GatewayIntent.MESSAGE_CONTENT}</b>
*
* @return The raw textual content of the message, containing unresolved Discord message formatting.
*/
@Nonnull
String getContentRaw();
/**
* Gets the textual content of this message using {@link #getContentDisplay()} and then strips it of markdown characters
* like {@literal *, **, __, ~~, ||} that provide text formatting. Any characters that match these but are not being used
* for formatting are escaped to prevent possible formatting.
*
* <p><b>Requires {@link net.dv8tion.jda.api.requests.GatewayIntent#MESSAGE_CONTENT GatewayIntent.MESSAGE_CONTENT}</b>
*
* @return The textual content from {@link #getContentDisplay()} with all text formatting characters removed or escaped.
*/
@Nonnull
String getContentStripped();
/**
* Creates an immutable List of {@link net.dv8tion.jda.api.entities.Invite Invite} codes
* that are included in this Message.
* <br>This will use the {@link java.util.regex.Pattern Pattern} provided
* under {@link #INVITE_PATTERN} to construct a {@link java.util.regex.Matcher Matcher} that will
* parse the {@link #getContentRaw()} output and include all codes it finds in a list.
*
* <p>You can use the codes to retrieve/validate invites via
* {@link net.dv8tion.jda.api.entities.Invite#resolve(JDA, String) Invite.resolve(JDA, String)}
*
* @return Immutable list of invite codes
*/
@Nonnull
List<String> getInvites();
/**
* Validation <a href="https://en.wikipedia.org/wiki/Cryptographic_nonce" target="_blank" >nonce</a> for this Message
* <br>This can be used to validate that a Message was properly sent to the Discord Service.
* <br>To set a nonce before sending you may use {@link MessageCreateAction#setNonce(String) MessageCreateAction.setNonce(String)}!
*
* @return The validation nonce
*
* @see MessageCreateAction#setNonce(String)
* @see <a href="https://en.wikipedia.org/wiki/Cryptographic_nonce" target="_blank">Cryptographic Nonce - Wikipedia</a>
*/
@Nullable
String getNonce();
/**
* Used to determine if this Message was received from a {@link MessageChannel}
* of the {@link net.dv8tion.jda.api.entities.channel.ChannelType ChannelType} specified.
*
* <p>Useful for restricting functionality to a certain type of channels.
*
* @param type
* The {@link ChannelType ChannelType} to check against.
*
* @return True if the {@link net.dv8tion.jda.api.entities.channel.ChannelType ChannelType} which this message was received
* from is the same as the one specified by {@code type}.
*/
boolean isFromType(@Nonnull ChannelType type);
/**
* Whether this message was sent in a {@link net.dv8tion.jda.api.entities.Guild Guild}.
* <br>If this is {@code false} then {@link #getGuild()} will throw an {@link java.lang.IllegalStateException}.
*
* @return True, if {@link #getChannelType()}.{@link ChannelType#isGuild() isGuild()} is true.
*/
default boolean isFromGuild()
{
return getChannelType().isGuild();
}
/**
* Gets the {@link net.dv8tion.jda.api.entities.channel.ChannelType ChannelType} that this message was received from.
*
* @return The ChannelType which this message was received from.
*/
@Nonnull
ChannelType getChannelType();
/**
* Indicates if this Message was sent by a {@link net.dv8tion.jda.api.entities.Webhook Webhook} instead of a
* {@link User User}.
* <br>Useful if you want to ignore non-users.
*
* @return True if this message was sent by a {@link net.dv8tion.jda.api.entities.Webhook Webhook}.
*/
boolean isWebhookMessage();
/**
* If this message is from an application-owned {@link net.dv8tion.jda.api.entities.Webhook Webhook} or
* is a response to an {@link net.dv8tion.jda.api.interactions.Interaction Interaction}, this will return
* the application's id.
*
* @return The application's id or {@code null} if this message was not sent by an application
*/
@Nullable
default String getApplicationId()
{
return getApplicationIdLong() == 0 ? null : Long.toUnsignedString(getApplicationIdLong());
}
/**
* If this message is from an application-owned {@link net.dv8tion.jda.api.entities.Webhook Webhook} or
* is a response to an {@link net.dv8tion.jda.api.interactions.Interaction Interaction}, this will return
* the application's id.
*
* @return The application's id or 0 if this message was not sent by an application
*/
long getApplicationIdLong();
/**
* Returns the {@link net.dv8tion.jda.api.entities.channel.middleman.MessageChannel MessageChannel} that this message was sent in.
*
* @return The MessageChannel of this Message
*/
@Nonnull
MessageChannelUnion getChannel();
/**
* Returns the {@link net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel GuildMessageChannel} that this message was sent in
* if it was sent in a Guild.
*
* @throws java.lang.IllegalStateException
* If this was not sent in a {@link net.dv8tion.jda.api.entities.Guild}.
*
* @return The MessageChannel of this Message
*/
@Nonnull
GuildMessageChannelUnion getGuildChannel();
/**
* The {@link Category Category} this
* message was sent in. This will always be {@code null} for DMs.
* <br>Equivalent to {@code getGuildChannel().getParentCategory()} if this was sent in a {@link net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel}.
*
* @return {@link net.dv8tion.jda.api.entities.channel.concrete.Category Category} for this message
*/
@Nullable
Category getCategory();
/**
* Returns the {@link net.dv8tion.jda.api.entities.Guild Guild} that this message was sent in.
* <br>This is just a shortcut to {@link #getGuildChannel()}{@link net.dv8tion.jda.api.entities.channel.middleman.GuildChannel#getGuild() .getGuild()}.
* <br><b>This is only valid if the Message was actually sent in a GuildMessageChannel.</b>
* <br>You can check the type of channel this message was sent from using {@link #isFromType(ChannelType)} or {@link #getChannelType()}.
*
* @throws java.lang.IllegalStateException
* If this was not sent in a {@link net.dv8tion.jda.api.entities.channel.middleman.GuildChannel}.
*
* @return The Guild this message was sent in
*
* @see #isFromGuild()
* @see #isFromType(ChannelType)
* @see #getChannelType()
*/
@Nonnull
Guild getGuild();
/**
* An immutable list of {@link net.dv8tion.jda.api.entities.Message.Attachment Attachments} that are attached to this message.
* <br>Most likely this will only ever be 1 {@link net.dv8tion.jda.api.entities.Message.Attachment Attachment} at most.
*
* <p><b>Requires {@link net.dv8tion.jda.api.requests.GatewayIntent#MESSAGE_CONTENT GatewayIntent.MESSAGE_CONTENT}</b>
*
* @return Immutable list of {@link net.dv8tion.jda.api.entities.Message.Attachment Attachments}.
*/
@Nonnull
List<Attachment> getAttachments();
/**
* An immutable list of {@link net.dv8tion.jda.api.entities.MessageEmbed MessageEmbeds} that are part of this Message.
*
* <p><b>Requires {@link net.dv8tion.jda.api.requests.GatewayIntent#MESSAGE_CONTENT GatewayIntent.MESSAGE_CONTENT}</b>
*
* @return Immutable list of all given MessageEmbeds.
*/
@Nonnull
List<MessageEmbed> getEmbeds();
/**
* Layouts of interactive components, usually {@link ActionRow ActionRows}.
* <br>You can use {@link MessageRequest#setComponents(LayoutComponent...)} to update these.
*
* <p><b>Requires {@link net.dv8tion.jda.api.requests.GatewayIntent#MESSAGE_CONTENT GatewayIntent.MESSAGE_CONTENT}</b>
*
* @return Immutable {@link List} of {@link LayoutComponent}
*
* @see #getActionRows()
* @see #getButtons()
* @see #getButtonById(String)
*/
@Nonnull
List<LayoutComponent> getComponents();
/**
* Rows of interactive components such as {@link Button Buttons}.
* <br>You can use {@link MessageRequest#setComponents(LayoutComponent...)} to update these.
*
* <p><b>Requires {@link net.dv8tion.jda.api.requests.GatewayIntent#MESSAGE_CONTENT GatewayIntent.MESSAGE_CONTENT}</b>
*
* @return Immutable {@link List} of {@link ActionRow}
*
* @see #getButtons()
* @see #getButtonById(String)
*/
@Nonnull
default List<ActionRow> getActionRows()
{
return getComponents()
.stream()
.filter(ActionRow.class::isInstance)
.map(ActionRow.class::cast)
.collect(Collectors.toList());
}
/**
* All {@link Button Buttons} attached to this message.
*
* <p><b>Requires {@link net.dv8tion.jda.api.requests.GatewayIntent#MESSAGE_CONTENT GatewayIntent.MESSAGE_CONTENT}</b>
*
* @return Immutable {@link List} of {@link Button Buttons}
*/
@Nonnull
default List<Button> getButtons()
{
return getComponents().stream()
.map(LayoutComponent::getButtons)
.flatMap(List::stream)
.collect(Collectors.toList());
}
/**
* Gets the {@link Button} with the specified ID.
*
* <p><b>Requires {@link net.dv8tion.jda.api.requests.GatewayIntent#MESSAGE_CONTENT GatewayIntent.MESSAGE_CONTENT}</b>
*
* @param id
* The id of the button
*
* @throws IllegalArgumentException
* If the id is null
*
* @return The {@link Button} or null of no button with that ID is present on this message
*/
@Nullable
default Button getButtonById(@Nonnull String id)
{
Checks.notNull(id, "Button ID");
return getButtons().stream()
.filter(it -> id.equals(it.getId()))
.findFirst().orElse(null);
}
/**
* All {@link Button Buttons} with the specified label attached to this message.
*
* <p><b>Requires {@link net.dv8tion.jda.api.requests.GatewayIntent#MESSAGE_CONTENT GatewayIntent.MESSAGE_CONTENT}</b>
*
* @param label
* The button label
* @param ignoreCase
* Whether to use {@link String#equalsIgnoreCase(String)} instead of {@link String#equals(Object)}
*
* @throws IllegalArgumentException
* If the provided label is null
*
* @return Immutable {@link List} of {@link Button Buttons} with the specified label
*/
@Nonnull
default List<Button> getButtonsByLabel(@Nonnull String label, boolean ignoreCase)
{
Checks.notNull(label, "Label");
Predicate<Button> filter;
if (ignoreCase)
filter = b -> label.equalsIgnoreCase(b.getLabel());
else
filter = b -> label.equals(b.getLabel());
return getButtons().stream()
.filter(filter)
.collect(Collectors.toList());
}
/**
* All {@link MessageReaction MessageReactions} that are on this Message.
*
* @return Immutable list of all MessageReactions on this message.
*
* @see MessageReaction
*/
@Nonnull
List<MessageReaction> getReactions();
/**
* All {@link StickerItem StickerItems} that are in this Message.
* <br>The returned StickerItems may only contain necessary information such as the sticker id, format type, name, and icon url.
*
* @return Immutable list of all StickerItems in this message.
*/
@Nonnull
List<StickerItem> getStickers();
/**
* Defines whether or not this Message triggers TTS (Text-To-Speech).
*
* @return If this message is TTS.
*/
boolean isTTS();
/**
* A {@link net.dv8tion.jda.api.entities.MessageActivity MessageActivity} that contains its type and party id.
*
* @return The activity, or {@code null} if no activity was added to the message.
*/
@Nullable
MessageActivity getActivity();
/**
* Edits this message and updates the content.
* <br>Any other fields of the message will remain unchanged,
* you can use {@link net.dv8tion.jda.api.utils.messages.MessageEditRequest#setReplace(boolean) replace(true)} to remove everything else (embeds/attachments/components).
*
* <p>The following {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} are possible:
* <ul>
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_ACCESS MISSING_ACCESS}
* <br>The request was attempted after the account lost access to the {@link net.dv8tion.jda.api.entities.Guild Guild}
* typically due to being kicked or removed, or after {@link net.dv8tion.jda.api.Permission#VIEW_CHANNEL Permission.VIEW_CHANNEL}
* was revoked in the {@link net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel GuildMessageChannel}</li>
*
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_MESSAGE UNKNOWN_MESSAGE}
* <br>The provided {@code messageId} is unknown in this MessageChannel, either due to the id being invalid, or
* the message it referred to has already been deleted.</li>
*
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_CHANNEL UNKNOWN_CHANNEL}
* <br>The request was attempted after the channel was deleted.</li>
* </ul>
*
* @param newContent
* The new content of the message, or empty string to remove content (assumes other fields exist like embeds)
*
* @throws UnsupportedOperationException
* If this is a system message
* @throws IllegalStateException
* If the message is not authored by this bot
* @throws IllegalArgumentException
* If null is provided or the new content is longer than {@value #MAX_CONTENT_LENGTH} characters
*
* @return {@link MessageEditAction}
*
* @see MessageChannel#editMessageById(long, CharSequence)
*/
@Nonnull
@CheckReturnValue
MessageEditAction editMessage(@Nonnull CharSequence newContent);
/**
* Edits this message using the provided {@link MessageEditData}.
* <br>You can use {@link net.dv8tion.jda.api.utils.messages.MessageEditBuilder MessageEditBuilder} to create a {@link MessageEditData} instance.
*
* <p>The following {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} are possible:
* <ul>
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_ACCESS MISSING_ACCESS}
* <br>The request was attempted after the account lost access to the {@link net.dv8tion.jda.api.entities.Guild Guild}
* typically due to being kicked or removed, or after {@link net.dv8tion.jda.api.Permission#VIEW_CHANNEL Permission.VIEW_CHANNEL}
* was revoked in the {@link GuildMessageChannel}</li>
*
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_MESSAGE UNKNOWN_MESSAGE}
* <br>The provided {@code messageId} is unknown in this MessageChannel, either due to the id being invalid, or
* the message it referred to has already been deleted.</li>
*
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_CHANNEL UNKNOWN_CHANNEL}
* <br>The request was attempted after the channel was deleted.</li>
* </ul>
*
* @param data
* The {@link MessageEditData} used to update the message
*
* @throws UnsupportedOperationException
* If this is a system message
* @throws IllegalStateException
* If the message is not authored by this bot
* @throws IllegalArgumentException
* If null is provided
*
* @return {@link MessageEditAction}
*
* @see net.dv8tion.jda.api.utils.messages.MessageEditBuilder MessageEditBuilder
* @see MessageChannel#editMessageById(long, MessageEditData)
*/
@Nonnull
@CheckReturnValue
MessageEditAction editMessage(@Nonnull MessageEditData data);
/**
* Edits this message using the provided {@link MessageEmbed MessageEmbeds}.
* <br>You can use {@link net.dv8tion.jda.api.EmbedBuilder EmbedBuilder} to create a {@link MessageEmbed} instance.
*
* <p>The following {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} are possible:
* <ul>
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_ACCESS MISSING_ACCESS}
* <br>The request was attempted after the account lost access to the {@link net.dv8tion.jda.api.entities.Guild Guild}
* typically due to being kicked or removed, or after {@link net.dv8tion.jda.api.Permission#VIEW_CHANNEL Permission.VIEW_CHANNEL}
* was revoked in the {@link GuildMessageChannel}</li>
*
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_MESSAGE UNKNOWN_MESSAGE}
* <br>The provided {@code messageId} is unknown in this MessageChannel, either due to the id being invalid, or
* the message it referred to has already been deleted.</li>
*
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_CHANNEL UNKNOWN_CHANNEL}
* <br>The request was attempted after the channel was deleted.</li>
* </ul>
*
* @param embeds
* The new {@link MessageEmbed MessageEmbeds} of the message, empty list to remove embeds
*
* @throws UnsupportedOperationException
* If this is a system message
* @throws IllegalStateException
* If the message is not authored by this bot
* @throws IllegalArgumentException
* <ul>
* <li>If {@code null} is provided</li>
* <li>If more than {@value Message#MAX_EMBED_COUNT} embeds are provided</li>
* </ul>
*
* @return {@link MessageEditAction}
*
* @see net.dv8tion.jda.api.EmbedBuilder EmbedBuilder
* @see MessageChannel#editMessageEmbedsById(long, Collection)
*/
@Nonnull
@CheckReturnValue
MessageEditAction editMessageEmbeds(@Nonnull Collection<? extends MessageEmbed> embeds);
/**
* Edits this message using the provided {@link MessageEmbed MessageEmbeds}.
* <br>You can use {@link net.dv8tion.jda.api.EmbedBuilder EmbedBuilder} to create a {@link MessageEmbed} instance.
*
* <p>The following {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} are possible:
* <ul>
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_ACCESS MISSING_ACCESS}
* <br>The request was attempted after the account lost access to the {@link net.dv8tion.jda.api.entities.Guild Guild}
* typically due to being kicked or removed, or after {@link net.dv8tion.jda.api.Permission#VIEW_CHANNEL Permission.VIEW_CHANNEL}
* was revoked in the {@link GuildMessageChannel}</li>
*
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_MESSAGE UNKNOWN_MESSAGE}
* <br>The provided {@code messageId} is unknown in this MessageChannel, either due to the id being invalid, or
* the message it referred to has already been deleted.</li>
*
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_CHANNEL UNKNOWN_CHANNEL}
* <br>The request was attempted after the channel was deleted.</li>
* </ul>
*
* @param embeds
* The new {@link MessageEmbed MessageEmbeds} of the message, or an empty list to remove all embeds
*
* @throws UnsupportedOperationException
* If this is a system message
* @throws IllegalStateException
* If the message is not authored by this bot
* @throws IllegalArgumentException
* <ul>
* <li>If {@code null} is provided</li>
* <li>If more than {@value Message#MAX_EMBED_COUNT} embeds are provided</li>
* </ul>
*
* @return {@link MessageEditAction}
*
* @see net.dv8tion.jda.api.EmbedBuilder EmbedBuilder
* @see MessageChannel#editMessageEmbedsById(long, Collection)
*/
@Nonnull
@CheckReturnValue
default MessageEditAction editMessageEmbeds(@Nonnull MessageEmbed... embeds)
{
Checks.noneNull(embeds, "MessageEmbeds");
return editMessageEmbeds(Arrays.asList(embeds));
}
/**
* Edits this message using the provided {@link LayoutComponent LayoutComponents}.
*
* <p>The following {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} are possible:
* <ul>
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_ACCESS MISSING_ACCESS}
* <br>The request was attempted after the account lost access to the {@link net.dv8tion.jda.api.entities.Guild Guild}
* typically due to being kicked or removed, or after {@link net.dv8tion.jda.api.Permission#VIEW_CHANNEL Permission.VIEW_CHANNEL}
* was revoked in the {@link GuildMessageChannel}</li>
*
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_MESSAGE UNKNOWN_MESSAGE}
* <br>The provided {@code messageId} is unknown in this MessageChannel, either due to the id being invalid, or
* the message it referred to has already been deleted.</li>
*
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_CHANNEL UNKNOWN_CHANNEL}
* <br>The request was attempted after the channel was deleted.</li>
* </ul>
*
* @param components
* The new {@link LayoutComponent LayoutComponents} of the message, or an empty list to remove all components
*
* @throws UnsupportedOperationException
* If this is a system message
* @throws IllegalStateException
* If the message is not authored by this bot
* @throws IllegalArgumentException
* <ul>
* <li>If {@code null} is provided</li>
* <li>If any of the components is not {@link LayoutComponent#isMessageCompatible() message compatible}</li>
* <li>If more than {@value Message#MAX_COMPONENT_COUNT} components are provided</li>
* </ul>
*
* @return {@link MessageEditAction}
*
* @see MessageChannel#editMessageComponentsById(long, Collection)
*/
@Nonnull
@CheckReturnValue
MessageEditAction editMessageComponents(@Nonnull Collection<? extends LayoutComponent> components);
/**
* Edits this message using the provided {@link LayoutComponent LayoutComponents}.
*
* <p>The following {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} are possible:
* <ul>
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_ACCESS MISSING_ACCESS}
* <br>The request was attempted after the account lost access to the {@link net.dv8tion.jda.api.entities.Guild Guild}
* typically due to being kicked or removed, or after {@link net.dv8tion.jda.api.Permission#VIEW_CHANNEL Permission.VIEW_CHANNEL}
* was revoked in the {@link GuildMessageChannel}</li>
*
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_MESSAGE UNKNOWN_MESSAGE}
* <br>The provided {@code messageId} is unknown in this MessageChannel, either due to the id being invalid, or
* the message it referred to has already been deleted.</li>
*
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_CHANNEL UNKNOWN_CHANNEL}
* <br>The request was attempted after the channel was deleted.</li>
* </ul>
*
* @param components
* The new {@link LayoutComponent LayoutComponents} of the message, empty list to remove all components
*
* @throws UnsupportedOperationException
* If this is a system message
* @throws IllegalStateException
* If the message is not authored by this bot
* @throws IllegalArgumentException
* <ul>
* <li>If {@code null} is provided</li>
* <li>If any of the components is not {@link LayoutComponent#isMessageCompatible() message compatible}</li>
* <li>If more than {@value Message#MAX_COMPONENT_COUNT} components are provided</li>
* </ul>
*
* @return {@link MessageEditAction}
*
* @see MessageChannel#editMessageComponentsById(long, Collection)
*/
@Nonnull
@CheckReturnValue
default MessageEditAction editMessageComponents(@Nonnull LayoutComponent... components)
{
Checks.noneNull(components, "Components");
return editMessageComponents(Arrays.asList(components));
}
/**
* Edits this message using the provided format arguments.
*
* <p>The following {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} are possible:
* <ul>
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_ACCESS MISSING_ACCESS}
* <br>The request was attempted after the account lost access to the {@link net.dv8tion.jda.api.entities.Guild Guild}
* typically due to being kicked or removed, or after {@link net.dv8tion.jda.api.Permission#VIEW_CHANNEL Permission.VIEW_CHANNEL}
* was revoked in the {@link GuildMessageChannel}</li>
*
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_MESSAGE UNKNOWN_MESSAGE}
* <br>The provided {@code messageId} is unknown in this MessageChannel, either due to the id being invalid, or
* the message it referred to has already been deleted.</li>
*
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_CHANNEL UNKNOWN_CHANNEL}
* <br>The request was attempted after the channel was deleted.</li>
* </ul>
*
* @param format
* Format String used to generate new Content
* @param args
* The arguments which should be used to format the given format String
*
* @throws IllegalArgumentException
* If provided {@code format} is {@code null} or blank.
* @throws UnsupportedOperationException
* If this is a system message
* @throws IllegalStateException
* If the message is not authored by this bot
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
* If this is a {@link GuildMessageChannel} and this account does not have
* {@link net.dv8tion.jda.api.Permission#VIEW_CHANNEL Permission.VIEW_CHANNEL}
* @throws java.util.IllegalFormatException
* If a format string contains an illegal syntax,
* a format specifier that is incompatible with the given arguments,
* insufficient arguments given the format string, or other illegal conditions.
* For specification of all possible formatting errors,
* see the <a href="../util/Formatter.html#detail">Details</a>
* section of the formatter class specification.