aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2020-09-24 09:00:07 -0400
committerRapptz <[email protected]>2020-09-24 09:00:54 -0400
commite4d7f44aa59d2bbd0f98f461e4b6504426a7eb8b (patch)
tree5a2e758db54330b4e9c49ec4bb12fa4f9077528d
parentFix typo in ValueError message (diff)
downloaddiscord.py-e4d7f44aa59d2bbd0f98f461e4b6504426a7eb8b.tar.xz
discord.py-e4d7f44aa59d2bbd0f98f461e4b6504426a7eb8b.zip
Make Intent class creation more intuitive
-rw-r--r--discord/flags.py20
-rw-r--r--discord/state.py2
-rw-r--r--docs/intents.rst4
3 files changed, 15 insertions, 11 deletions
diff --git a/discord/flags.py b/discord/flags.py
index 981d1b30..38a6ac3f 100644
--- a/discord/flags.py
+++ b/discord/flags.py
@@ -368,9 +368,6 @@ class Intents(BaseFlags):
run your bot. To make use of this, it is passed to the ``intents`` keyword
argument of :class:`Client`.
- A default instance of this class has everything enabled except :attr:`presences`
- and :attr:`members`.
-
.. versionadded:: 1.5
.. container:: operations
@@ -399,12 +396,7 @@ class Intents(BaseFlags):
__slots__ = ()
def __init__(self, **kwargs):
- # Change the default value to everything being enabled
- # except presences and members
- bits = max(self.VALID_FLAGS.values()).bit_length()
- self.value = (1 << bits) - 1
- self.presences = False
- self.members = False
+ self.value = self.DEFAULT_VALUE
for key, value in kwargs.items():
if key not in self.VALID_FLAGS:
raise TypeError('%r is not a valid flag name.' % key)
@@ -426,6 +418,16 @@ class Intents(BaseFlags):
self.value = self.DEFAULT_VALUE
return self
+ @classmethod
+ def default(cls):
+ """A factory method that creates a :class:`Intents` with everything enabled
+ except :attr:`presences` and :attr:`members`.
+ """
+ self = cls.all()
+ self.presences = False
+ self.members = False
+ return self
+
@flag_value
def guilds(self):
""":class:`bool`: Whether guild related events are enabled.
diff --git a/discord/state.py b/discord/state.py
index 3257d41d..507226cc 100644
--- a/discord/state.py
+++ b/discord/state.py
@@ -137,7 +137,7 @@ class ConnectionState:
if not isinstance(intents, Intents):
raise TypeError('intents parameter must be Intent not %r' % type(intents))
else:
- intents = Intents()
+ intents = Intents.default()
try:
chunk_guilds = options['fetch_offline_members']
diff --git a/docs/intents.rst b/docs/intents.rst
index 13d58221..6e18e738 100644
--- a/docs/intents.rst
+++ b/docs/intents.rst
@@ -21,7 +21,9 @@ For example, if you want a bot that functions without spammy events like presenc
.. code-block:: python3
import discord
- intents = discord.Intents(typing=False, presences=False)
+ intents = discord.Intents.default()
+ intents.typing = False
+ intents.presences = False
Note that this doesn't enable :attr:`Intents.members` since it's a privileged intent.