Skip to content

Commit 344d54e

Browse files
committed
Added discord.Client support
1 parent 8bc3af6 commit 344d54e

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.idea
22
__pycache__
33
test.py
4+
test2.py
45
docs/_build

discord_slash/client.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ class SlashCommand:
1111
"""
1212
Slash command extension class.
1313
14-
:param client: discord.py Bot class. Although it accepts :class:`discord.Client` at init, using it is not allowed since :class:`discord.Client` doesn't support :func:`add_listener`.
14+
:param client: discord.py Client or Bot instance.
1515
:type client: Union[discord.Client, discord.ext.commands.Bot]
16-
:param auto_register: Whether to register commands automatically. Default `False`.
16+
:param auto_register: Whether to register commands automatically. Default `False`. Currently not implemented.
1717
:type auto_register: bool
1818
1919
:ivar _discord: Discord client of this client.
@@ -25,14 +25,16 @@ class SlashCommand:
2525
def __init__(self,
2626
client: typing.Union[discord.Client, commands.Bot],
2727
auto_register: bool = False):
28-
if isinstance(client, discord.Client) and not isinstance(client, commands.Bot):
29-
raise Exception("Currently only commands.Bot is supported.")
3028
self._discord = client
3129
self.commands = {}
3230
self.req = http.SlashCommandRequest()
3331
self.logger = logging.getLogger("discord_slash")
3432
self.auto_register = auto_register
35-
self._discord.add_listener(self.on_socket_response)
33+
if not isinstance(client, commands.Bot):
34+
self.logger.info("Detected discord.Client! Overriding on_socket_response.")
35+
self._discord.on_socket_response = self.on_socket_response
36+
else:
37+
self._discord.add_listener(self.on_socket_response)
3638

3739
def slash(self,
3840
*,

0 commit comments

Comments
 (0)