-
-
Notifications
You must be signed in to change notification settings - Fork 735
/
Message.java
2683 lines (2565 loc) · 129 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.api.JDA;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.exceptions.HttpException;
import net.dv8tion.jda.api.exceptions.InsufficientPermissionException;
import net.dv8tion.jda.api.requests.RestAction;
import net.dv8tion.jda.api.requests.restaction.AuditableRestAction;
import net.dv8tion.jda.api.requests.restaction.MessageAction;
import net.dv8tion.jda.api.requests.restaction.pagination.ReactionPaginationAction;
import net.dv8tion.jda.api.utils.AttachmentOption;
import net.dv8tion.jda.internal.JDAImpl;
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.OkHttpClient;
import okhttp3.Request;
import org.apache.commons.collections4.Bag;
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.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.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>
*
* <h2>Message Differences</h2>
* There are 3 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>
* <li><b>Data Message</b>
* <br>This type is produced by {@link net.dv8tion.jda.api.MessageBuilder MessageBuilder}
* and only holds sendable information such as content or nonce. These messages do not allow
* any modifications via RestActions or information that is generated when sent such as the id to be used.</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.
*
* <h1>Formattable</h1>
* 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 net.dv8tion.jda.api.MessageBuilder MessageBuilder
* @see MessageChannel#sendMessage(Message)
*
* @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
{
/**
* The maximum sendable file size (8 MiB)
*
* @see MessageAction#addFile(java.io.File, net.dv8tion.jda.api.utils.AttachmentOption...) MessageAction.addFile(...)
*/
int MAX_FILE_SIZE = 8 << 20;
/**
* The maximum sendable file size for nitro (50 MiB)
*
* @see MessageAction#addFile(java.io.File, net.dv8tion.jda.api.utils.AttachmentOption...) MessageAction.addFile(...)
*/
int MAX_FILE_SIZE_NITRO = 50 << 20;
/**
* The maximum amount of files sendable within a single message ({@value})
*
* @see MessageAction#addFile(java.io.File, net.dv8tion.jda.api.utils.AttachmentOption...) MessageAction.addFile(...)
*/
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 MessageAction#append(CharSequence) MessageAction.append(...)
*/
int MAX_CONTENT_LENGTH = 2000;
/**
* The maximum amount of reactions that can be added to one message ({@value})
*
* @see Message#addReaction(String)
* @see Message#addReaction(net.dv8tion.jda.api.entities.Emote)
*/
int MAX_REACTIONS = 20;
/**
* 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.
*
* <h2>Groups</h2>
* <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);
/**
* 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.
*
* @return The referenced message, or null
*/
@Nullable
Message getReferencedMessage();
/**
* An immutable list of all mentioned {@link net.dv8tion.jda.api.entities.User Users}.
* <br>If no user was mentioned, this list is empty. Elements are sorted in order of appearance. This only
* counts direct mentions of the user and not mentions through roles or the everyone tag.
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
*
* @return immutable list of mentioned users
*/
@Nonnull
List<User> getMentionedUsers();
/**
* A {@link org.apache.commons.collections4.Bag Bag} of mentioned users.
* <br>This can be used to retrieve the amount of times a user was mentioned in this message. This only
* counts direct mentions of the user and not mentions through roles or the everyone tag.
*
* <h2>Example</h2>
* <pre>{@code
* public void sendCount(Message msg)
* {
* List<User> mentions = msg.getMentionedUsers(); // distinct list, in order of appearance
* Bag<User> count = msg.getMentionedUsersBag();
* StringBuilder content = new StringBuilder();
* for (User user : mentions)
* {
* content.append(user.getAsTag())
* .append(": ")
* .append(count.getCount(user))
* .append("\n");
* }
* msg.getChannel().sendMessage(content.toString()).queue();
* }
* }</pre>
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
*
* @return {@link org.apache.commons.collections4.Bag Bag} of mentioned users
*
* @see #getMentionedUsers()
*/
@Nonnull
Bag<User> getMentionedUsersBag();
/**
* A immutable list of all mentioned {@link net.dv8tion.jda.api.entities.TextChannel TextChannels}.
* <br>If none were mentioned, this list is empty. Elements are sorted in order of appearance.
*
* <p><b>This may include TextChannels from other {@link net.dv8tion.jda.api.entities.Guild Guilds}</b>
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
*
* @return immutable list of mentioned TextChannels
*/
@Nonnull
List<TextChannel> getMentionedChannels();
/**
* A {@link org.apache.commons.collections4.Bag Bag} of mentioned channels.
* <br>This can be used to retrieve the amount of times a channel was mentioned in this message.
*
* <h2>Example</h2>
* <pre>{@code
* public void sendCount(Message msg)
* {
* List<TextChannel> mentions = msg.getMentionedTextChannels(); // distinct list, in order of appearance
* Bag<TextChannel> count = msg.getMentionedTextChannelsBag();
* StringBuilder content = new StringBuilder();
* for (TextChannel channel : mentions)
* {
* content.append("#")
* .append(channel.getName())
* .append(": ")
* .append(count.getCount(channel))
* .append("\n");
* }
* msg.getChannel().sendMessage(content.toString()).queue();
* }
* }</pre>
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
*
* @return {@link org.apache.commons.collections4.Bag Bag} of mentioned channels
*
* @see #getMentionedChannels()
*/
@Nonnull
Bag<TextChannel> getMentionedChannelsBag();
/**
* A immutable list of all mentioned {@link net.dv8tion.jda.api.entities.Role Roles}.
* <br>If none were mentioned, this list is empty. Elements are sorted in order of appearance. This only
* counts direct mentions of the role and not mentions through the everyone tag.
*
* <p><b>This may include Roles from other {@link net.dv8tion.jda.api.entities.Guild Guilds}</b>
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
*
* @return immutable list of mentioned Roles
*/
@Nonnull
List<Role> getMentionedRoles();
/**
* A {@link org.apache.commons.collections4.Bag Bag} of mentioned roles.
* <br>This can be used to retrieve the amount of times a role was mentioned in this message. This only
* counts direct mentions of the role and not mentions through the everyone tag.
* If a role is not {@link net.dv8tion.jda.api.entities.Role#isMentionable() mentionable} it will not be included.
*
* <h2>Example</h2>
* <pre>{@code
* public void sendCount(Message msg)
* {
* List<Role> mentions = msg.getMentionedRoles(); // distinct list, in order of appearance
* Bag<Role> count = msg.getMentionedRolesBag();
* StringBuilder content = new StringBuilder();
* for (Role role : mentions)
* {
* content.append(role.getName())
* .append(": ")
* .append(count.getCount(role))
* .append("\n");
* }
* msg.getChannel().sendMessage(content.toString()).queue();
* }
* }</pre>
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
*
* @return {@link org.apache.commons.collections4.Bag Bag} of mentioned roles
*
* @see #getMentionedRoles()
*/
@Nonnull
Bag<Role> getMentionedRolesBag();
/**
* Creates an immutable list of {@link net.dv8tion.jda.api.entities.Member Members}
* representing the users of {@link #getMentionedUsers()} in the specified
* {@link net.dv8tion.jda.api.entities.Guild Guild}.
* <br>This is only a convenience method and will skip all users that are not in the specified
* Guild.
*
* @param guild
* Non-null {@link net.dv8tion.jda.api.entities.Guild Guild}
* that will be used to retrieve Members.
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
* @throws java.lang.IllegalArgumentException
* If the specified Guild is {@code null}
*
* @return Immutable list of mentioned Members
*
* @since 3.4.0
*/
@Nonnull
List<Member> getMentionedMembers(@Nonnull Guild guild);
/**
* Creates an immutable list of {@link net.dv8tion.jda.api.entities.Member Members}
* representing the users of {@link #getMentionedUsers()} in the
* {@link net.dv8tion.jda.api.entities.Guild Guild} this Message was sent in.
* <br>This is only a convenience method and will skip all users that are not in the specified Guild.
* <br>It will provide the {@link #getGuild()} output Guild to {@link #getMentionedMembers(Guild)}.
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
* @throws java.lang.IllegalStateException
* If this message was not sent in a {@link net.dv8tion.jda.api.entities.TextChannel TextChannel}
*
* @return Immutable list of mentioned Members
*
* @since 3.4.0
*/
@Nonnull
List<Member> getMentionedMembers();
/**
* Combines all instances of {@link net.dv8tion.jda.api.entities.IMentionable IMentionable}
* filtered by the specified {@link net.dv8tion.jda.api.entities.Message.MentionType MentionType} values.
* <br>This does not include {@link #getMentionedMembers()} to avoid duplicates.
*
* <p>If no MentionType values are given this will fallback to all types.
*
* @param types
* Amount of {@link net.dv8tion.jda.api.entities.Message.MentionType MentionTypes}
* to include in the list of mentions
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
* @throws java.lang.IllegalArgumentException
* If provided with {@code null}
*
* @return Immutable list of filtered {@link net.dv8tion.jda.api.entities.IMentionable IMentionable} instances
*
* @since 3.4.0
*/
@Nonnull
List<IMentionable> getMentions(@Nonnull MentionType... types);
/**
* Checks if given {@link net.dv8tion.jda.api.entities.IMentionable IMentionable}
* was mentioned in this message in any way (@User, @everyone, @here, @Role).
* <br>If no filtering {@link net.dv8tion.jda.api.entities.Message.MentionType MentionTypes} are
* specified this will fallback to all mention types.
*
* <p>{@link Message.MentionType#HERE MentionType.HERE} and {@link Message.MentionType#EVERYONE MentionType.EVERYONE}
* will only be checked, if the given {@link net.dv8tion.jda.api.entities.IMentionable IMentionable} is of type
* {@link net.dv8tion.jda.api.entities.User User} or {@link net.dv8tion.jda.api.entities.Member Member}.
* <br>Online status of Users/Members is <b>NOT</b> considered when checking {@link Message.MentionType#HERE MentionType.HERE}.
*
* @param mentionable
* The mentionable entity to check on.
* @param types
* The types to include when checking whether this type was mentioned.
* This will be used with {@link #getMentions(Message.MentionType...) getMentions(MentionType...)}
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
*
* @return True, if the given mentionable was mentioned in this message
*/
boolean isMentioned(@Nonnull IMentionable mentionable, @Nonnull MentionType... types);
/**
* Indicates if this Message mentions everyone using @everyone or @here.
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
*
* @return True, if message is mentioning everyone
*/
boolean mentionsEveryone();
/**
* Returns whether or not this Message has been edited before.
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
*
* @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}.
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
*
* @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
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
*
* @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 TextChannel.</b> This will return {@code null}
* if the message was not sent in a TextChannel, 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 MessageChannel#retrieveMessageById(long)} or similar means,
* unless the member is already cached.
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
*
* @return Message author, or {@code null} if the message was not sent in a TextChannel, 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.
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
*
* @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 net.dv8tion.jda.api.entities.User Users} / {@link net.dv8tion.jda.api.entities.Member Members}
* to their @Username/@Nickname format,
* <br>{@link net.dv8tion.jda.api.entities.TextChannel TextChannels} to their #ChannelName format,
* <br>{@link net.dv8tion.jda.api.entities.Role Roles} to their @RoleName format
* <br>{@link net.dv8tion.jda.api.entities.Emote Emotes} (not emojis!) to their {@code :name:} format.
*
* <p>If you want the actual Content (mentions as {@literal <@id>}), use {@link #getContentRaw()} instead
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
*
* @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>.
*
* @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.
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
*
* @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)}
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
*
* @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 net.dv8tion.jda.api.MessageBuilder#setNonce(String) MessageBuilder.setNonce(String)}!
*
* @return The validation nonce
*
* @since 3.4.0
*
* @see net.dv8tion.jda.api.MessageBuilder#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 net.dv8tion.jda.api.entities.MessageChannel MessageChannel}
* of the {@link net.dv8tion.jda.api.entities.ChannelType ChannelType} specified.
* <br>This will always be false for {@link net.dv8tion.jda.api.entities.ChannelType#VOICE} as Messages can't be sent to
* {@link net.dv8tion.jda.api.entities.VoiceChannel VoiceChannels}.
*
* <p>Useful for restricting functionality to a certain type of channels.
*
* @param type
* The {@link net.dv8tion.jda.api.entities.ChannelType ChannelType} to check against.
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
*
* @return True if the {@link net.dv8tion.jda.api.entities.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.ChannelType ChannelType} that this message was received from.
* <br>This will never be {@link net.dv8tion.jda.api.entities.ChannelType#VOICE} as Messages can't be sent to
* {@link net.dv8tion.jda.api.entities.VoiceChannel VoiceChannels}.
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
*
* @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 net.dv8tion.jda.api.entities.User User}.
* <br>Useful if you want to ignore non-users.
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
*
* @return True if this message was sent by a {@link net.dv8tion.jda.api.entities.Webhook Webhook}.
*/
boolean isWebhookMessage();
/**
* Returns the {@link net.dv8tion.jda.api.entities.MessageChannel MessageChannel} that this message was sent in.
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
*
* @return The MessageChannel of this Message
*/
@Nonnull
MessageChannel getChannel();
/**
* Returns the {@link net.dv8tion.jda.api.entities.PrivateChannel PrivateChannel} that this message was sent in.
* <br><b>This is only valid if the Message was actually sent in a PrivateChannel.</b>
* <br>You can check the type of channel this message was sent from using {@link #isFromType(ChannelType)} or {@link #getChannelType()}.
*
* <p>Use {@link #getChannel()} for an ambiguous {@link net.dv8tion.jda.api.entities.MessageChannel MessageChannel}
* if you do not need functionality specific to {@link net.dv8tion.jda.api.entities.PrivateChannel PrivateChannel}.
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
* @throws java.lang.IllegalStateException
* If this was not sent in a {@link net.dv8tion.jda.api.entities.PrivateChannel}.
*
* @return The PrivateChannel this message was sent in
*
* @see #isFromGuild()
* @see #isFromType(ChannelType)
* @see #getChannelType()
*/
@Nonnull
PrivateChannel getPrivateChannel();
/**
* Returns the {@link net.dv8tion.jda.api.entities.TextChannel TextChannel} that this message was sent in.
* <br><b>This is only valid if the Message was actually sent in a TextChannel.</b>
* <br>You can check the type of channel this message was sent from using {@link #isFromType(ChannelType)} or {@link #getChannelType()}.
*
* <p>Use {@link #getChannel()} for an ambiguous {@link net.dv8tion.jda.api.entities.MessageChannel MessageChannel}
* if you do not need functionality specific to {@link net.dv8tion.jda.api.entities.TextChannel TextChannel}.
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
* @throws java.lang.IllegalStateException
* If this was not sent in a {@link net.dv8tion.jda.api.entities.TextChannel}.
*
* @return The TextChannel this message was sent in
*
* @see #isFromGuild()
* @see #isFromType(ChannelType)
* @see #getChannelType()
*/
@Nonnull
TextChannel getTextChannel();
/**
* The {@link net.dv8tion.jda.api.entities.Category Category} this
* message was sent in. This will always be {@code null} for DMs.
* <br>Equivalent to {@code getTextChannel().getParent()} if this was sent in a {@link net.dv8tion.jda.api.entities.TextChannel}.
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
*
* @return {@link net.dv8tion.jda.api.entities.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 #getTextChannel()}.{@link net.dv8tion.jda.api.entities.TextChannel#getGuild() getGuild()}.
* <br><b>This is only valid if the Message was actually sent in a TextChannel.</b>
* <br>You can check the type of channel this message was sent from using {@link #isFromType(ChannelType)} or {@link #getChannelType()}.
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
* @throws java.lang.IllegalStateException
* If this was not sent in a {@link net.dv8tion.jda.api.entities.TextChannel}.
*
* @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.
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
*
* @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.
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
*
* @return Immutable list of all given MessageEmbeds.
*/
@Nonnull
List<MessageEmbed> getEmbeds();
/**
* All {@link net.dv8tion.jda.api.entities.Emote Emotes} used in this Message.
* <br><b>This only includes Custom Emotes, not unicode Emojis.</b> JDA classifies Emotes as the Custom Emojis uploaded
* to a Guild and retrievable with {@link net.dv8tion.jda.api.entities.Guild#getEmotes()}. These are not the same
* as the unicode emojis that Discord also supports. Elements are sorted in order of appearance.
*
* <p><b><u>Unicode emojis are not included as {@link net.dv8tion.jda.api.entities.Emote Emote}!</u></b>
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
*
* @return An immutable list of the Emotes used in this message (example match {@literal <:jda:230988580904763393>})
*/
@Nonnull
List<Emote> getEmotes();
/**
* A {@link org.apache.commons.collections4.Bag Bag} of emotes used in this message.
* <br>This can be used to retrieve the amount of times an emote was used in this message.
*
* <h2>Example</h2>
* <pre>{@code
* public void sendCount(Message msg)
* {
* List<Emote> emotes = msg.getEmotes(); // distinct list, in order of appearance
* Bag<Emote> count = msg.getEmotesBag();
* StringBuilder content = new StringBuilder();
* for (Emote emote : emotes)
* {
* content.append(emote.getName())
* .append(": ")
* .append(count.getCount(role))
* .append("\n");
* }
* msg.getChannel().sendMessage(content.toString()).queue();
* }
* }</pre>
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
*
* @return {@link org.apache.commons.collections4.Bag Bag} of used emotes
*
* @see #getEmotes()
*/
@Nonnull
Bag<Emote> getEmotesBag();
/**
* All {@link net.dv8tion.jda.api.entities.MessageReaction MessageReactions} that are on this Message.
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
*
* @return Immutable list of all MessageReactions on this message.
*/
@Nonnull
List<MessageReaction> getReactions();
/**
* All {@link net.dv8tion.jda.api.entities.MessageSticker MessageStickers} that are in this Message.
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
*
* @return Immutable list of all MessageStickers in this message.
*/
@Nonnull
List<MessageSticker> 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's content to the provided String.
* <br><b>Messages can only be edited by the account that sent them!</b>.
*
* <p>This message instance will not be updated by this operation, please use the response message instead.
*
* <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 edit was attempted after the account lost access to the {@link net.dv8tion.jda.api.entities.Guild Guild}
* typically due to being kicked or removed.</li>
*
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_PERMISSIONS MISSING_PERMISSIONS}
* <br>The edit was attempted after the account lost {@link net.dv8tion.jda.api.Permission#MESSAGE_WRITE Permission.MESSAGE_WRITE} in
* the {@link net.dv8tion.jda.api.entities.TextChannel TextChannel}.</li>
*
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_MESSAGE UNKNOWN_MESSAGE}
* <br>The edit was attempted after the Message had been deleted.</li>
* </ul>
*
* @param newContent
* the new content of the Message
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
* @throws java.lang.IllegalStateException
* If the message attempting to be edited was not created by the currently logged in account, or if
* {@code newContent}'s length is 0 or greater than 2000.
*
* @return {@link MessageAction MessageAction}
* <br>The {@link net.dv8tion.jda.api.entities.Message Message} with the updated content
*/
@Nonnull
@CheckReturnValue
MessageAction editMessage(@Nonnull CharSequence newContent);
/**
* Edits this Message's content to the provided {@link net.dv8tion.jda.api.entities.MessageEmbed MessageEmbed}.
* <br><b>Messages can only be edited by the account that sent them!</b>.
*
* <p>This message instance will not be updated by this operation, please use the response message instead.
*
* <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 edit was attempted after the account lost access to the {@link net.dv8tion.jda.api.entities.Guild Guild}
* typically due to being kicked or removed.</li>
*
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_PERMISSIONS MISSING_PERMISSIONS}
* <br>The edit was attempted after the account lost {@link net.dv8tion.jda.api.Permission#MESSAGE_WRITE Permission.MESSAGE_WRITE} in
* the {@link net.dv8tion.jda.api.entities.TextChannel TextChannel}.</li>
*
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_MESSAGE UNKNOWN_MESSAGE}
* <br>The edit was attempted after the Message had been deleted.</li>
* </ul>
*
* @param newContent
* the new content of the Message
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
* @throws java.lang.IllegalStateException
* If the message attempting to be edited was not created by the currently logged in account, or
* if the passed-in embed is {@code null}
* or not {@link net.dv8tion.jda.api.entities.MessageEmbed#isSendable() sendable}
*
* @return {@link MessageAction MessageAction}
* <br>The {@link net.dv8tion.jda.api.entities.Message Message} with the updated content
*/
@Nonnull
@CheckReturnValue
MessageAction editMessage(@Nonnull MessageEmbed newContent);
/**
* Edits this Message's content to the provided format.
* <br>Shortcut for {@link net.dv8tion.jda.api.MessageBuilder#appendFormat(String, Object...)}.
* <br><b>Messages can only be edited by the account that sent them!</b>.
*
* <p>This message instance will not be updated by this operation, please use the response message instead.
*
* <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 edit was attempted after the account lost access to the {@link net.dv8tion.jda.api.entities.Guild Guild}
* typically due to being kicked or removed.</li>
*
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_PERMISSIONS MISSING_PERMISSIONS}
* <br>The edit was attempted after the account lost {@link net.dv8tion.jda.api.Permission#MESSAGE_WRITE Permission.MESSAGE_WRITE} in
* the {@link net.dv8tion.jda.api.entities.TextChannel TextChannel}.</li>
*
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_MESSAGE UNKNOWN_MESSAGE}
* <br>The edit was attempted after the Message had been deleted.</li>
* </ul>
*
* @param format
* Format String used to generate the Message's content via
* {@link net.dv8tion.jda.api.MessageBuilder#appendFormat(String, Object...)} specification
* @param args
* The arguments to use in order to be converted in the format string
*
* @throws java.lang.UnsupportedOperationException
* If this is not a Received Message from {@link net.dv8tion.jda.api.entities.MessageType#DEFAULT MessageType.DEFAULT}
* @throws IllegalArgumentException
* If the provided format String is {@code null} or blank, or if
* the created message exceeds the 2000 character limit
* @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.
* @throws IllegalStateException
* If the message attempting to be edited was not created by the currently logged in account
*
* @return {@link MessageAction MessageAction}
* <br>The {@link net.dv8tion.jda.api.entities.Message Message} with the updated content
*/
@Nonnull
@CheckReturnValue
MessageAction editMessageFormat(@Nonnull String format, @Nonnull Object... args);
/**
* Edits this Message's content to the provided {@link net.dv8tion.jda.api.entities.Message Message}.
* <br><b>Messages can only be edited by the account that sent them!</b>.
*
* <p>This message instance will not be updated by this operation, please use the response message instead.
*
* <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 edit was attempted after the account lost access to the {@link net.dv8tion.jda.api.entities.Guild Guild}
* typically due to being kicked or removed.</li>
*
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#MISSING_PERMISSIONS MISSING_PERMISSIONS}
* <br>The edit was attempted after the account lost {@link net.dv8tion.jda.api.Permission#MESSAGE_WRITE Permission.MESSAGE_WRITE} in
* the {@link net.dv8tion.jda.api.entities.TextChannel TextChannel}.</li>
*
* <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_MESSAGE UNKNOWN_MESSAGE}
* <br>The edit was attempted after the Message had been deleted.</li>