mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-18 23:15:48 +00:00
Require passing intents to Client and its subclasses
This commit is contained in:
parent
7770972041
commit
76cc2c2272
@ -140,9 +140,11 @@ class Client:
|
||||
intents: :class:`Intents`
|
||||
The intents that you want to enable for the session. This is a way of
|
||||
disabling and enabling certain gateway events from triggering and being sent.
|
||||
If not given, defaults to a regularly constructed :class:`Intents` class.
|
||||
|
||||
.. versionadded:: 1.5
|
||||
|
||||
.. versionchanged:: 2.0
|
||||
Parameter is now required.
|
||||
member_cache_flags: :class:`MemberCacheFlags`
|
||||
Allows for finer control over how the library caches members.
|
||||
If not given, defaults to cache as much as possible with the
|
||||
@ -203,7 +205,7 @@ class Client:
|
||||
The websocket gateway the client is currently connected to. Could be ``None``.
|
||||
"""
|
||||
|
||||
def __init__(self, **options: Any) -> None:
|
||||
def __init__(self, *, intents: Intents, **options: Any) -> None:
|
||||
self.loop: asyncio.AbstractEventLoop = _loop
|
||||
# self.ws is set in the connect method
|
||||
self.ws: DiscordWebSocket = None # type: ignore
|
||||
@ -232,7 +234,7 @@ class Client:
|
||||
}
|
||||
|
||||
self._enable_debug_events: bool = options.pop('enable_debug_events', False)
|
||||
self._connection: ConnectionState = self._get_state(**options)
|
||||
self._connection: ConnectionState = self._get_state(intents=intents, **options)
|
||||
self._connection.shard_count = self.shard_count
|
||||
self._closed: bool = False
|
||||
self._ready: asyncio.Event = MISSING
|
||||
|
@ -155,12 +155,14 @@ class BotBase(GroupMixin[None]):
|
||||
def __init__(
|
||||
self,
|
||||
command_prefix: PrefixType[BotT],
|
||||
*,
|
||||
help_command: Optional[HelpCommand] = _default,
|
||||
tree_cls: Type[app_commands.CommandTree[Any]] = app_commands.CommandTree,
|
||||
description: Optional[str] = None,
|
||||
intents: discord.Intents,
|
||||
**options: Any,
|
||||
) -> None:
|
||||
super().__init__(**options)
|
||||
super().__init__(intents=intents, **options)
|
||||
self.command_prefix: PrefixType[BotT] = command_prefix
|
||||
self.extra_events: Dict[str, List[CoroFunc]] = {}
|
||||
# Self doesn't have the ClientT bound, but since this is a mixin it technically does
|
||||
|
@ -48,6 +48,7 @@ from typing import TYPE_CHECKING, Any, Callable, Tuple, Type, Optional, List, Di
|
||||
if TYPE_CHECKING:
|
||||
from .gateway import DiscordWebSocket
|
||||
from .activity import BaseActivity
|
||||
from .flags import Intents
|
||||
|
||||
__all__ = (
|
||||
'AutoShardedClient',
|
||||
@ -316,10 +317,10 @@ class AutoShardedClient(Client):
|
||||
if TYPE_CHECKING:
|
||||
_connection: AutoShardedConnectionState
|
||||
|
||||
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
||||
def __init__(self, *args: Any, intents: Intents, **kwargs: Any) -> None:
|
||||
kwargs.pop('shard_id', None)
|
||||
self.shard_ids: Optional[List[int]] = kwargs.pop('shard_ids', None)
|
||||
super().__init__(*args, **kwargs)
|
||||
super().__init__(*args, intents=intents, **kwargs)
|
||||
|
||||
if self.shard_ids is not None:
|
||||
if self.shard_count is None:
|
||||
|
@ -115,6 +115,29 @@ With this change, constructor of :class:`Client` no longer accepts ``connector``
|
||||
In parallel with this change, changes were made to loading and unloading of commands extension extensions and cogs,
|
||||
see :ref:`migrating_2_0_commands_extension_cog_async` for more information.
|
||||
|
||||
Intents Are Now Required
|
||||
--------------------------
|
||||
|
||||
In earlier versions, the ``intents`` keyword argument was optional and defaulted to :meth:`Intents.default`. In order to better educate users on their intents and to also make it more explicit, this parameter is now required to pass in.
|
||||
|
||||
For example:
|
||||
|
||||
.. code-block:: python3
|
||||
|
||||
# before
|
||||
client = discord.Client()
|
||||
|
||||
# after
|
||||
intents = discord.Intents.default()
|
||||
client = discord.Client(intents=intents)
|
||||
|
||||
This change applies to **all** subclasses of :class:`Client`.
|
||||
|
||||
- :class:`AutoShardedClient`
|
||||
- :class:`~discord.ext.commands.Bot`
|
||||
- :class:`~discord.ext.commands.AutoShardedBot`
|
||||
|
||||
|
||||
Abstract Base Classes Changes
|
||||
-------------------------------
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user