mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-08 04:38:42 +00:00
Make Intent class creation more intuitive
This commit is contained in:
parent
dc6e9e7fd6
commit
e4d7f44aa5
@ -368,9 +368,6 @@ class Intents(BaseFlags):
|
|||||||
run your bot. To make use of this, it is passed to the ``intents`` keyword
|
run your bot. To make use of this, it is passed to the ``intents`` keyword
|
||||||
argument of :class:`Client`.
|
argument of :class:`Client`.
|
||||||
|
|
||||||
A default instance of this class has everything enabled except :attr:`presences`
|
|
||||||
and :attr:`members`.
|
|
||||||
|
|
||||||
.. versionadded:: 1.5
|
.. versionadded:: 1.5
|
||||||
|
|
||||||
.. container:: operations
|
.. container:: operations
|
||||||
@ -399,12 +396,7 @@ class Intents(BaseFlags):
|
|||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
# Change the default value to everything being enabled
|
self.value = self.DEFAULT_VALUE
|
||||||
# except presences and members
|
|
||||||
bits = max(self.VALID_FLAGS.values()).bit_length()
|
|
||||||
self.value = (1 << bits) - 1
|
|
||||||
self.presences = False
|
|
||||||
self.members = False
|
|
||||||
for key, value in kwargs.items():
|
for key, value in kwargs.items():
|
||||||
if key not in self.VALID_FLAGS:
|
if key not in self.VALID_FLAGS:
|
||||||
raise TypeError('%r is not a valid flag name.' % key)
|
raise TypeError('%r is not a valid flag name.' % key)
|
||||||
@ -426,6 +418,16 @@ class Intents(BaseFlags):
|
|||||||
self.value = self.DEFAULT_VALUE
|
self.value = self.DEFAULT_VALUE
|
||||||
return self
|
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
|
@flag_value
|
||||||
def guilds(self):
|
def guilds(self):
|
||||||
""":class:`bool`: Whether guild related events are enabled.
|
""":class:`bool`: Whether guild related events are enabled.
|
||||||
|
@ -137,7 +137,7 @@ class ConnectionState:
|
|||||||
if not isinstance(intents, Intents):
|
if not isinstance(intents, Intents):
|
||||||
raise TypeError('intents parameter must be Intent not %r' % type(intents))
|
raise TypeError('intents parameter must be Intent not %r' % type(intents))
|
||||||
else:
|
else:
|
||||||
intents = Intents()
|
intents = Intents.default()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
chunk_guilds = options['fetch_offline_members']
|
chunk_guilds = options['fetch_offline_members']
|
||||||
|
@ -21,7 +21,9 @@ For example, if you want a bot that functions without spammy events like presenc
|
|||||||
.. code-block:: python3
|
.. code-block:: python3
|
||||||
|
|
||||||
import discord
|
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.
|
Note that this doesn't enable :attr:`Intents.members` since it's a privileged intent.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user