From 1e7f139313108047ab2870004357084af2e6152f Mon Sep 17 00:00:00 2001 From: Rapptz Date: Sun, 28 Mar 2021 08:28:39 -0400 Subject: [PATCH] Add support for setting application_id --- discord/client.py | 12 ++++++++++++ discord/state.py | 17 +++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/discord/client.py b/discord/client.py index 180152a10..6d80c9d8e 100644 --- a/discord/client.py +++ b/discord/client.py @@ -113,6 +113,8 @@ class Client: Integer starting at ``0`` and less than :attr:`.shard_count`. shard_count: Optional[:class:`int`] The total number of shards. + application_id: :class:`int` + The client's application ID. 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. @@ -306,6 +308,16 @@ class Client: """ return self._connection.voice_clients + @property + def application_id(self): + """Optional[:class:`int`]: The client's application ID. + + If this is not passed via ``__init__`` then this is retrieved + through the gateway when an event contains the data. Usually + after :func:`on_connect` is called. + """ + return self._connection.application_id + def is_ready(self): """:class:`bool`: Specifies if the client's internal cache is ready for use.""" return self._ready.is_set() diff --git a/discord/state.py b/discord/state.py index 3d74b1743..2aa12d68e 100644 --- a/discord/state.py +++ b/discord/state.py @@ -113,6 +113,7 @@ class ConnectionState: self.hooks = hooks self.shard_count = None self._ready_task = None + self.application_id = utils._get_as_snowflake(options, 'application_id') self.heartbeat_timeout = options.get('heartbeat_timeout', 60.0) self.guild_ready_timeout = options.get('guild_ready_timeout', 2.0) if self.guild_ready_timeout < 0: @@ -452,6 +453,14 @@ class ConnectionState: self.user = user = ClientUser(state=self, data=data['user']) self._users[user.id] = user + if self.application_id is None: + try: + application = data['application'] + except KeyError: + pass + else: + self.application_id = utils._get_as_snowflake(application, 'id') + for guild_data in data['guilds']: self._add_guild_from_data(guild_data) @@ -1153,6 +1162,14 @@ class AutoShardedConnectionState(ConnectionState): self.user = user = ClientUser(state=self, data=data['user']) self._users[user.id] = user + if self.application_id is None: + try: + application = data['application'] + except KeyError: + pass + else: + self.application_id = utils._get_as_snowflake(application, 'id') + for guild_data in data['guilds']: self._add_guild_from_data(guild_data)