forked from Pycord-Development/pycord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflags.py
1815 lines (1326 loc) · 54.9 KB
/
flags.py
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
"""
The MIT License (MIT)
Copyright (c) 2015-2021 Rapptz
Copyright (c) 2021-present Pycord Development
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
from __future__ import annotations
from typing import Any, Callable, ClassVar, Iterator, TypeVar, overload
from .enums import UserFlags
__all__ = (
"SystemChannelFlags",
"MessageFlags",
"AttachmentFlags",
"PublicUserFlags",
"Intents",
"MemberCacheFlags",
"ApplicationFlags",
"ChannelFlags",
"SKUFlags",
"RoleFlags",
"MemberFlags",
)
FV = TypeVar("FV", bound="flag_value")
BF = TypeVar("BF", bound="BaseFlags")
class flag_value:
def __init__(self, func: Callable[[Any], int]):
self.flag = func(None)
self.__doc__ = func.__doc__
@overload
def __get__(self: FV, instance: None, owner: type[BF]) -> FV: ...
@overload
def __get__(self, instance: BF, owner: type[BF]) -> bool: ...
def __get__(self, instance: BF | None, owner: type[BF]) -> Any:
if instance is None:
return self
return instance._has_flag(self.flag)
def __set__(self, instance: BF, value: bool) -> None:
instance._set_flag(self.flag, value)
def __repr__(self):
return f"<flag_value flag={self.flag!r}>"
class alias_flag_value(flag_value):
pass
def fill_with_flags(*, inverted: bool = False):
def decorator(cls: type[BF]):
cls.VALID_FLAGS = {
name: value.flag
for name, value in cls.__dict__.items()
if isinstance(value, flag_value)
}
if inverted:
max_bits = max(cls.VALID_FLAGS.values()).bit_length()
cls.DEFAULT_VALUE = -1 + (2**max_bits)
else:
cls.DEFAULT_VALUE = 0
return cls
return decorator
# n.b. flags must inherit from this and use the decorator above
class BaseFlags:
VALID_FLAGS: ClassVar[dict[str, int]]
DEFAULT_VALUE: ClassVar[int]
value: int
__slots__ = ("value",)
def __init__(self, **kwargs: bool):
self.value = self.DEFAULT_VALUE
for key, value in kwargs.items():
if key not in self.VALID_FLAGS:
raise TypeError(f"{key!r} is not a valid flag name.")
setattr(self, key, value)
@classmethod
def _from_value(cls, value):
self = cls.__new__(cls)
self.value = value
return self
def __eq__(self, other: Any) -> bool:
return isinstance(other, self.__class__) and self.value == other.value
def __hash__(self) -> int:
return hash(self.value)
def __repr__(self) -> str:
return f"<{self.__class__.__name__} value={self.value}>"
def __iter__(self) -> Iterator[tuple[str, bool]]:
for name, value in self.__class__.__dict__.items():
if isinstance(value, alias_flag_value):
continue
if isinstance(value, flag_value):
yield name, self._has_flag(value.flag)
def __and__(self, other):
if isinstance(other, self.__class__):
return self.__class__._from_value(self.value & other.value)
elif isinstance(other, flag_value):
return self.__class__._from_value(self.value & other.flag)
else:
raise TypeError(
f"'&' not supported between instances of {type(self)} and {type(other)}"
)
def __or__(self, other):
if isinstance(other, self.__class__):
return self.__class__._from_value(self.value | other.value)
elif isinstance(other, flag_value):
return self.__class__._from_value(self.value | other.flag)
else:
raise TypeError(
f"'|' not supported between instances of {type(self)} and {type(other)}"
)
def __add__(self, other):
try:
return self | other
except TypeError:
raise TypeError(
f"'+' not supported between instances of {type(self)} and {type(other)}"
)
def __sub__(self, other):
if isinstance(other, self.__class__):
return self.__class__._from_value(self.value & ~other.value)
elif isinstance(other, flag_value):
return self.__class__._from_value(self.value & ~other.flag)
else:
raise TypeError(
f"'-' not supported between instances of {type(self)} and {type(other)}"
)
def __invert__(self):
return self.__class__._from_value(~self.value)
__rand__: Callable[[BaseFlags | flag_value], bool] = __and__
__ror__: Callable[[BaseFlags | flag_value], bool] = __or__
__radd__: Callable[[BaseFlags | flag_value], bool] = __add__
__rsub__: Callable[[BaseFlags | flag_value], bool] = __sub__
def _has_flag(self, o: int) -> bool:
return (self.value & o) == o
def _set_flag(self, o: int, toggle: bool) -> None:
if toggle:
self.value |= o
else:
self.value &= ~o
@fill_with_flags(inverted=True)
class SystemChannelFlags(BaseFlags):
r"""Wraps up a Discord system channel flag value.
Similar to :class:`Permissions`\, the properties provided are two way.
You can set and retrieve individual bits using the properties as if they
were regular bools. This allows you to edit the system flags easily.
To construct an object you can pass keyword arguments denoting the flags
to enable or disable.
.. container:: operations
.. describe:: x == y
Checks if two flags are equal.
.. describe:: x != y
Checks if two flags are not equal.
.. describe:: x + y
Adds two flags together. Equivalent to ``x | y``.
.. describe:: x - y
Subtracts two flags from each other.
.. describe:: x | y
Returns the union of two flags. Equivalent to ``x + y``.
.. describe:: x & y
Returns the intersection of two flags.
.. describe:: ~x
Returns the inverse of a flag.
.. describe:: hash(x)
Return the flag's hash.
.. describe:: iter(x)
Returns an iterator of ``(name, value)`` pairs. This allows it
to be, for example, constructed as a dict or a list of pairs.
Attributes
-----------
value: :class:`int`
The raw value. This value is a bit array field of a 53-bit integer
representing the currently available flags. You should query
flags via the properties rather than using this raw value.
"""
__slots__ = ()
# For some reason the flags for system channels are "inverted"
# ergo, if they're set then it means "suppress" (off in the GUI toggle)
# Since this is counter-intuitive from an API perspective and annoying
# these will be inverted automatically
def _has_flag(self, o: int) -> bool:
return (self.value & o) != o
def _set_flag(self, o: int, toggle: bool) -> None:
if toggle:
self.value &= ~o
else:
self.value |= o
@flag_value
def join_notifications(self):
""":class:`bool`: Returns ``True`` if the system channel is used for member join notifications."""
return 1
@flag_value
def premium_subscriptions(self):
""":class:`bool`: Returns ``True`` if the system channel is used for "Nitro boosting" notifications."""
return 2
@flag_value
def guild_reminder_notifications(self):
""":class:`bool`: Returns ``True`` if the system channel is used for server setup helpful tips notifications.
.. versionadded:: 2.0
"""
return 4
@flag_value
def join_notification_replies(self):
""":class:`bool`: Returns ``True`` if the system channel is allowing member join sticker replies.
.. versionadded:: 2.0
"""
return 8
@fill_with_flags()
class MessageFlags(BaseFlags):
r"""Wraps up a Discord Message flag value.
See :class:`SystemChannelFlags`.
.. container:: operations
.. describe:: x == y
Checks if two flags are equal.
.. describe:: x != y
Checks if two flags are not equal.
.. describe:: x + y
Adds two flags together. Equivalent to ``x | y``.
.. describe:: x - y
Subtracts two flags from each other.
.. describe:: x | y
Returns the union of two flags. Equivalent to ``x + y``.
.. describe:: x & y
Returns the intersection of two flags.
.. describe:: ~x
Returns the inverse of a flag.
.. describe:: hash(x)
Return the flag's hash.
.. describe:: iter(x)
Returns an iterator of ``(name, value)`` pairs. This allows it
to be, for example, constructed as a dict or a list of pairs.
.. versionadded:: 1.3
Attributes
-----------
value: :class:`int`
The raw value. This value is a bit array field of a 53-bit integer
representing the currently available flags. You should query
flags via the properties rather than using this raw value.
"""
__slots__ = ()
@flag_value
def crossposted(self):
""":class:`bool`: Returns ``True`` if the message is the original crossposted message."""
return 1
@flag_value
def is_crossposted(self):
""":class:`bool`: Returns ``True`` if the message was crossposted from another channel."""
return 2
@flag_value
def suppress_embeds(self):
""":class:`bool`: Returns ``True`` if the message's embeds have been suppressed."""
return 4
@flag_value
def source_message_deleted(self):
""":class:`bool`: Returns ``True`` if the source message for this crosspost has been deleted."""
return 8
@flag_value
def urgent(self):
""":class:`bool`: Returns ``True`` if the source message is an urgent message.
An urgent message is one sent by Discord Trust and Safety.
"""
return 16
@flag_value
def has_thread(self):
""":class:`bool`: Returns ``True`` if the source message is associated with a thread.
.. versionadded:: 2.0
"""
return 32
@flag_value
def ephemeral(self):
""":class:`bool`: Returns ``True`` if the source message is ephemeral.
.. versionadded:: 2.0
"""
return 64
@flag_value
def loading(self):
""":class:`bool`: Returns ``True`` if the source message is deferred.
The user sees a 'thinking' state.
.. versionadded:: 2.0
"""
return 128
@flag_value
def failed_to_mention_some_roles_in_thread(self):
""":class:`bool`: Returns ``True`` if some roles are failed to mention in a thread.
.. versionadded:: 2.0
"""
return 256
@flag_value
def suppress_notifications(self):
""":class:`bool`: Returns ``True`` if the source message does not trigger push and desktop notifications.
Users will still receive mentions.
.. versionadded:: 2.4
"""
return 4096
@flag_value
def is_voice_message(self):
""":class:`bool`: Returns ``True`` if this message is a voice message.
.. versionadded:: 2.5
"""
return 8192
@fill_with_flags()
class PublicUserFlags(BaseFlags):
r"""Wraps up the Discord User Public flags.
.. container:: operations
.. describe:: x == y
Checks if two PublicUserFlags are equal.
.. describe:: x != y
Checks if two PublicUserFlags are not equal.
.. describe:: x + y
Adds two flags together. Equivalent to ``x | y``.
.. describe:: x - y
Subtracts two flags from each other.
.. describe:: x | y
Returns the union of two flags. Equivalent to ``x + y``.
.. describe:: x & y
Returns the intersection of two flags.
.. describe:: ~x
Returns the inverse of a flag.
.. describe:: hash(x)
Return the flag's hash.
.. describe:: iter(x)
Returns an iterator of ``(name, value)`` pairs. This allows it
to be, for example, constructed as a dict or a list of pairs.
Note that aliases are not shown.
.. versionadded:: 1.4
Attributes
-----------
value: :class:`int`
The raw value. This value is a bit array field of a 53-bit integer
representing the currently available flags. You should query
flags via the properties rather than using this raw value.
"""
__slots__ = ()
@flag_value
def staff(self):
""":class:`bool`: Returns ``True`` if the user is a Discord Employee."""
return UserFlags.staff.value
@flag_value
def partner(self):
""":class:`bool`: Returns ``True`` if the user is a Discord Partner."""
return UserFlags.partner.value
@flag_value
def hypesquad(self):
""":class:`bool`: Returns ``True`` if the user is a HypeSquad Events member."""
return UserFlags.hypesquad.value
@flag_value
def bug_hunter(self):
""":class:`bool`: Returns ``True`` if the user is a Bug Hunter"""
return UserFlags.bug_hunter.value
@flag_value
def premium_promo_dismissed(self):
""":class:`bool`: Returns ``True`` if the user is marked as dismissed Nitro promotion"""
return UserFlags.premium_promo_dismissed.value
@flag_value
def hypesquad_bravery(self):
""":class:`bool`: Returns ``True`` if the user is a HypeSquad Bravery member."""
return UserFlags.hypesquad_bravery.value
@flag_value
def hypesquad_brilliance(self):
""":class:`bool`: Returns ``True`` if the user is a HypeSquad Brilliance member."""
return UserFlags.hypesquad_brilliance.value
@flag_value
def hypesquad_balance(self):
""":class:`bool`: Returns ``True`` if the user is a HypeSquad Balance member."""
return UserFlags.hypesquad_balance.value
@flag_value
def early_supporter(self):
""":class:`bool`: Returns ``True`` if the user is an Early Supporter."""
return UserFlags.early_supporter.value
@flag_value
def team_user(self):
""":class:`bool`: Returns ``True`` if the user is a Team User."""
return UserFlags.team_user.value
@flag_value
def system(self):
""":class:`bool`: Returns ``True`` if the user is a system user (i.e. represents Discord officially)."""
return UserFlags.system.value
@flag_value
def bug_hunter_level_2(self):
""":class:`bool`: Returns ``True`` if the user is a Bug Hunter Level 2"""
return UserFlags.bug_hunter_level_2.value
@flag_value
def verified_bot(self):
""":class:`bool`: Returns ``True`` if the user is a Verified Bot."""
return UserFlags.verified_bot.value
@flag_value
def verified_bot_developer(self):
""":class:`bool`: Returns ``True`` if the user is an Early Verified Bot Developer."""
return UserFlags.verified_bot_developer.value
@alias_flag_value
def early_verified_bot_developer(self):
""":class:`bool`: An alias for :attr:`verified_bot_developer`.
.. versionadded:: 1.5
"""
return UserFlags.verified_bot_developer.value
@flag_value
def discord_certified_moderator(self):
""":class:`bool`: Returns ``True`` if the user is a Discord Certified Moderator.
.. versionadded:: 2.0
"""
return UserFlags.discord_certified_moderator.value
@flag_value
def bot_http_interactions(self):
""":class:`bool`: Returns ``True`` if the bot has set an interactions endpoint url.
.. versionadded:: 2.0
"""
return UserFlags.bot_http_interactions.value
@flag_value
def active_developer(self):
""":class:`bool`: Returns ``True`` if the user is an Active Developer.
.. versionadded:: 2.3
"""
return UserFlags.active_developer.value
def all(self) -> list[UserFlags]:
"""List[:class:`UserFlags`]: Returns all public flags the user has."""
return [
public_flag
for public_flag in UserFlags
if self._has_flag(public_flag.value)
]
@fill_with_flags()
class Intents(BaseFlags):
r"""Wraps up a Discord gateway intent flag.
Similar to :class:`Permissions`\, the properties provided are two way.
You can set and retrieve individual bits using the properties as if they
were regular bools.
To construct an object you can pass keyword arguments denoting the flags
to enable or disable.
This is used to disable certain gateway features that are unnecessary to
run your bot. To make use of this, it is passed to the ``intents`` keyword
argument of :class:`Client`.
.. versionadded:: 1.5
.. container:: operations
.. describe:: x == y
Checks if two flags are equal.
.. describe:: x != y
Checks if two flags are not equal.
.. describe:: x + y
Adds two flags together. Equivalent to ``x | y``.
.. describe:: x - y
Subtracts two flags from each other.
.. describe:: x | y
Returns the union of two flags. Equivalent to ``x + y``.
.. describe:: x & y
Returns the intersection of two flags.
.. describe:: ~x
Returns the inverse of a flag.
.. describe:: hash(x)
Return the flag's hash.
.. describe:: iter(x)
Returns an iterator of ``(name, value)`` pairs. This allows it
to be, for example, constructed as a dict or a list of pairs.
Attributes
-----------
value: :class:`int`
The raw value. You should query flags via the properties
rather than using this raw value.
"""
__slots__ = ()
def __init__(self, **kwargs: bool):
self.value = self.DEFAULT_VALUE
for key, value in kwargs.items():
if key not in self.VALID_FLAGS:
raise TypeError(f"{key!r} is not a valid flag name.")
setattr(self, key, value)
@classmethod
def all(cls: type[Intents]) -> Intents:
"""A factory method that creates a :class:`Intents` with everything enabled."""
value = sum({1 << (flag.bit_length() - 1) for flag in cls.VALID_FLAGS.values()})
self = cls.__new__(cls)
self.value = value
return self
@classmethod
def none(cls: type[Intents]) -> Intents:
"""A factory method that creates a :class:`Intents` with everything disabled."""
self = cls.__new__(cls)
self.value = self.DEFAULT_VALUE
return self
@classmethod
def default(cls: type[Intents]) -> Intents:
"""A factory method that creates a :class:`Intents` with everything enabled
except :attr:`presences`, :attr:`members`, and :attr:`message_content`.
"""
self = cls.all()
self.presences = False
self.members = False
self.message_content = False
return self
@flag_value
def guilds(self):
""":class:`bool`: Whether guild related events are enabled.
This corresponds to the following events:
- :func:`on_guild_join`
- :func:`on_guild_remove`
- :func:`on_guild_available`
- :func:`on_guild_unavailable`
- :func:`on_guild_channel_update`
- :func:`on_guild_channel_create`
- :func:`on_guild_channel_delete`
- :func:`on_guild_channel_pins_update`
This also corresponds to the following attributes and classes in terms of cache:
- :attr:`Client.guilds`
- :class:`Guild` and all its attributes.
- :meth:`Client.get_channel`
- :meth:`Client.get_all_channels`
It is highly advisable to leave this intent enabled for your bot to function.
"""
return 1 << 0
@flag_value
def members(self):
""":class:`bool`: Whether guild member related events are enabled.
This corresponds to the following events:
- :func:`on_member_join`
- :func:`on_member_remove`
- :func:`on_raw_member_remove`
- :func:`on_member_update`
- :func:`on_user_update`
This also corresponds to the following attributes and classes in terms of cache:
- :meth:`Client.get_all_members`
- :meth:`Client.get_user`
- :meth:`Guild.chunk`
- :meth:`Guild.fetch_members`
- :meth:`Guild.get_member`
- :attr:`Guild.members`
- :attr:`Member.roles`
- :attr:`Member.nick`
- :attr:`Member.premium_since`
- :attr:`User.name`
- :attr:`User.avatar`
- :attr:`User.discriminator`
For more information go to the :ref:`member intent documentation <need_members_intent>`.
.. note::
This intent is privileged, meaning that bots in over 100 guilds that require this
intent would need to request this intent on the Developer Portal.
"""
return 1 << 1
@alias_flag_value
def bans(self):
""":class:`bool`: Alias of :attr:`.moderation`.
.. versionchanged:: 2.5
Changed to an alias.
"""
return 1 << 2
@flag_value
def moderation(self):
""":class:`bool`: Whether guild moderation related events are enabled.
This corresponds to the following events:
- :func:`on_audit_log_entry`
- :func:`on_member_ban`
- :func:`on_member_unban`
This does not correspond to any attributes or classes in the library in terms of cache.
"""
return 1 << 2
@flag_value
def emojis(self):
""":class:`bool`: Alias of :attr:`.emojis_and_stickers`.
.. versionchanged:: 2.0
Changed to an alias.
"""
return 1 << 3
@alias_flag_value
def emojis_and_stickers(self):
""":class:`bool`: Whether guild emoji and sticker related events are enabled.
.. versionadded:: 2.0
This corresponds to the following events:
- :func:`on_guild_emojis_update`
- :func:`on_guild_stickers_update`
This also corresponds to the following attributes and classes in terms of cache:
- :class:`GuildEmoji`
- :class:`GuildSticker`
- :meth:`Client.get_emoji`
- :meth:`Client.get_sticker`
- :meth:`Client.emojis`
- :meth:`Client.stickers`
- :attr:`Guild.emojis`
- :attr:`Guild.stickers`
"""
return 1 << 3
@flag_value
def integrations(self):
""":class:`bool`: Whether guild integration related events are enabled.
This corresponds to the following events:
- :func:`on_guild_integrations_update`
- :func:`on_integration_create`
- :func:`on_integration_update`
- :func:`on_raw_integration_delete`
This does not correspond to any attributes or classes in the library in terms of cache.
"""
return 1 << 4
@flag_value
def webhooks(self):
""":class:`bool`: Whether guild webhook related events are enabled.
This corresponds to the following events:
- :func:`on_webhooks_update`
This does not correspond to any attributes or classes in the library in terms of cache.
"""
return 1 << 5
@flag_value
def invites(self):
""":class:`bool`: Whether guild invite related events are enabled.
This corresponds to the following events:
- :func:`on_invite_create`
- :func:`on_invite_delete`
This does not correspond to any attributes or classes in the library in terms of cache.
"""
return 1 << 6
@flag_value
def voice_states(self):
""":class:`bool`: Whether guild voice state related events are enabled.
This corresponds to the following events:
- :func:`on_voice_state_update`
This also corresponds to the following attributes and classes in terms of cache:
- :attr:`VoiceChannel.members`
- :attr:`VoiceChannel.voice_states`
- :attr:`StageChannel.members`
- :attr:`StageChannel.speakers`
- :attr:`StageChannel.listeners`
- :attr:`StageChannel.moderators`
- :attr:`StageChannel.voice_states`
- :attr:`Member.voice`
.. note::
This intent is required to connect to voice.
"""
return 1 << 7
@flag_value
def presences(self):
""":class:`bool`: Whether guild presence related events are enabled.
This corresponds to the following events:
- :func:`on_presence_update`
This also corresponds to the following attributes and classes in terms of cache:
- :attr:`Member.activities`
- :attr:`Member.status`
- :attr:`Member.raw_status`
For more information go to the :ref:`presence intent documentation <need_presence_intent>`.
.. note::
This intent is privileged, meaning that bots in over 100 guilds that require this
intent would need to request this intent on the Developer Portal.
"""
return 1 << 8
@alias_flag_value
def messages(self):
""":class:`bool`: Whether guild and direct message related events are enabled.
This is a shortcut to set or get both :attr:`guild_messages` and :attr:`dm_messages`.
This corresponds to the following events:
- :func:`on_message` (both guilds and DMs)
- :func:`on_message_edit` (both guilds and DMs)
- :func:`on_message_delete` (both guilds and DMs)
- :func:`on_raw_message_delete` (both guilds and DMs)
- :func:`on_raw_message_edit` (both guilds and DMs)
This also corresponds to the following attributes and classes in terms of cache:
- :class:`Message`
- :attr:`Client.cached_messages`
- :meth:`Client.get_message`
- :attr:`Client.polls`
- :meth:`Client.get_poll`
Note that due to an implicit relationship this also corresponds to the following events:
- :func:`on_reaction_add` (both guilds and DMs)
- :func:`on_reaction_remove` (both guilds and DMs)
- :func:`on_reaction_clear` (both guilds and DMs)
.. note::
:attr:`message_content` is required to receive the actual content of guild messages.
"""
return (1 << 9) | (1 << 12)
@flag_value
def guild_messages(self):
""":class:`bool`: Whether guild message related events are enabled.
See also :attr:`dm_messages` for DMs or :attr:`messages` for both.
This corresponds to the following events:
- :func:`on_message` (only for guilds)
- :func:`on_message_edit` (only for guilds)
- :func:`on_message_delete` (only for guilds)
- :func:`on_raw_message_delete` (only for guilds)
- :func:`on_raw_message_edit` (only for guilds)
This also corresponds to the following attributes and classes in terms of cache:
- :class:`Message`
- :attr:`Client.cached_messages` (only for guilds)
- :meth:`Client.get_message` (only for guilds)
- :attr:`Client.polls` (only for guilds)
- :meth:`Client.get_poll` (only for guilds)
Note that due to an implicit relationship this also corresponds to the following events:
- :func:`on_reaction_add` (only for guilds)
- :func:`on_reaction_remove` (only for guilds)
- :func:`on_reaction_clear` (only for guilds)
Without the :attr:`message_content` intent enabled,
the following fields are either an empty string or empty array:
- :attr:`Message.content`
- :attr:`Message.embeds`
- :attr:`Message.attachments`
- :attr:`Message.components`
- :attr:`Message.poll`
For more information go to the :ref:`message content intent documentation <need_message_content_intent>`.
"""
return 1 << 9
@flag_value
def dm_messages(self):
""":class:`bool`: Whether direct message related events are enabled.
See also :attr:`guild_messages` for guilds or :attr:`messages` for both.
This corresponds to the following events:
- :func:`on_message` (only for DMs)
- :func:`on_message_edit` (only for DMs)
- :func:`on_message_delete` (only for DMs)
- :func:`on_raw_message_delete` (only for DMs)
- :func:`on_raw_message_edit` (only for DMs)
This also corresponds to the following attributes and classes in terms of cache:
- :class:`Message`
- :attr:`Client.cached_messages` (only for DMs)
- :meth:`Client.get_message` (only for DMs)
- :attr:`Client.polls` (only for DMs)
- :meth:`Client.get_poll` (only for DMs)
Note that due to an implicit relationship this also corresponds to the following events:
- :func:`on_reaction_add` (only for DMs)
- :func:`on_reaction_remove` (only for DMs)
- :func:`on_reaction_clear` (only for DMs)
"""
return 1 << 12
@alias_flag_value
def reactions(self):
""":class:`bool`: Whether guild and direct message reaction related events are enabled.
This is a shortcut to set or get both :attr:`guild_reactions` and :attr:`dm_reactions`.
This corresponds to the following events:
- :func:`on_reaction_add` (both guilds and DMs)
- :func:`on_reaction_remove` (both guilds and DMs)
- :func:`on_reaction_clear` (both guilds and DMs)
- :func:`on_raw_reaction_add` (both guilds and DMs)
- :func:`on_raw_reaction_remove` (both guilds and DMs)
- :func:`on_raw_reaction_clear` (both guilds and DMs)
This also corresponds to the following attributes and classes in terms of cache:
- :attr:`Message.reactions` (both guild and DM messages)
"""
return (1 << 10) | (1 << 13)
@flag_value
def guild_reactions(self):
""":class:`bool`: Whether guild message reaction related events are enabled.