Skip to content
This repository was archived by the owner on Mar 8, 2022. It is now read-only.

Commit f68b455

Browse files
committed
fixed #89 again and fixed on_cog_sync warning
1 parent d0d80e6 commit f68b455

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,14 @@ You can find more (and better) examples [here](https://github.com/discord-py-ui/
175175

176176
# Changelog
177177

178+
- <details>
179+
180+
## **Fixed**
181+
182+
- #94 (again 💀)
183+
184+
</details>
185+
178186
- <details>
179187
<summary>4.2.7<summary>
180188

discord_ui/client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from .slash.tools import ParseMethod, cache_data, format_name, handle_options, handle_thing
77
from .slash.http import create_global_command, create_guild_command, delete_global_command, delete_guild_command, delete_guild_commands, edit_global_command, edit_guild_command, get_command, get_command_permissions, get_global_commands, get_guild_commands, delete_global_commands, get_id, update_command_permissions
88
from .slash.types import AdditionalType, CommandType, ContextCommand, MessageCommand, OptionType, SlashCommand, SlashOption, SlashSubcommand, UserCommand
9-
from .tools import MISSING, _none, _or, get_index, setup_logger
9+
from .tools import MISSING, _none, _or, get_index, setup_logger, get
1010
from .http import jsonifyMessage, BetterRoute, send_files
1111
from .receive import ComponentContext, Interaction, Message, PressedButton, SelectedMenu, SlashedContext, WebhookMessage, SlashedCommand, SlashedSubCommand, getMessage
1212
from .override import override_dpy as override_it
@@ -124,7 +124,7 @@ def add_cog_override(*args, **kwargs):
124124
self._add_to_cache(com)
125125
old_add(*args, **kwargs)
126126
if self.ready is True and sync_on_cog is True:
127-
self._discord.loop.create_task(self.sync_commands(self.delete_unused))
127+
self._discord.loop.run_until_complete(self.sync_commands(self.delete_unused))
128128
self._discord.add_cog = add_cog_override
129129

130130
old_remove = self._discord.remove_cog
@@ -135,7 +135,7 @@ def remove_cog_override(*args, **kwargs):
135135
self._remove_from_cache(com)
136136
old_remove(*args, **kwargs)
137137
if self.ready is True and sync_on_cog is True:
138-
self._discord.loop.create_task(self.sync_commands(self.delete_unused))
138+
self._discord.loop.run_until_complete(self.sync_commands(self.delete_unused))
139139
self._discord.remove_cog = remove_cog_override
140140

141141
async def on_connect():
@@ -397,7 +397,7 @@ async def _get_guild_commands(self, guild_id: str) -> List[dict]:
397397
logging.debug("getting guild commands in " + str(guild_id))
398398
return await get_guild_commands(self._discord, guild_id)
399399

400-
def gather_commands(self):
400+
def gather_commands(self) -> Dict[str, SlashCommand]:
401401
commands = self.commands.copy()
402402
for _base in self.subcommands:
403403
# get first base
@@ -644,7 +644,7 @@ async def edit_command(self, old_name, typ: Literal["slash", 1, "user", 2, "mess
644644
else:
645645
await self.create_command(command)
646646
self._set_command(old_name, command)
647-
647+
648648
def _get_command(self, name, typ: Literal["slash", 1, "user", 2, "message", 3]) -> SlashCommand:
649649
typ = CommandType.from_string(typ)
650650
if typ == CommandType.SLASH:

discord_ui/override.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,8 @@ def override_dpy():
3939

4040
#region message override
4141
async def send(self: discord.TextChannel, content=None, **kwargs) -> Message:
42-
channel_id = self.id if not isinstance(self, commands.Context) else self.channel.id
43-
44-
channel = None
45-
if isinstance(self, (discord.Member, discord.User)) and self.dm_channel is None:
46-
channel = await self.create_dm()
47-
channel_id = channel.id
48-
49-
route = BetterRoute("POST", f"/channels/{channel_id}/messages")
42+
channel = await self._get_channel()
43+
route = BetterRoute("POST", f"/channels/{channel.id}/messages")
5044

5145
r = None
5246
if kwargs.get("file") is None and kwargs.get("files") is None:
@@ -60,8 +54,6 @@ async def send(self: discord.TextChannel, content=None, **kwargs) -> Message:
6054
payload = jsonifyMessage(content=content, **kwargs)
6155
r = await send_files(route, files=files, payload=payload, http=self._state.http)
6256

63-
if channel is None:
64-
channel = self if not isinstance(self, commands.Context) else self.channel
6557
msg = Message(state=self._state, channel=channel, data=r)
6658
if kwargs.get("delete_after") is not None:
6759
await msg.delete(delay=kwargs.get("delete_after"))

discord_ui/receive.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from .errors import InvalidEvent, OutOfValidRange, WrongType
22
from .slash.errors import AlreadyDeferred, EphemeralDeletion
3-
from .slash.types import ContextCommand, SlashCommand, SlashPermission, SlashSubcommand
3+
from .slash.types import ContextCommand, OptionType, SlashCommand, SlashPermission, SlashSubcommand
44
from .tools import MISSING, setup_logger, _none
55
from .http import BetterRoute, jsonifyMessage, send_files
66
from .components import ActionRow, Button, Component, LinkButton, SelectMenu, SelectOption, make_component
@@ -317,7 +317,18 @@ class SlashedSubCommand(SlashedCommand, SlashSubcommand):
317317
"""A Sub-:class:`~SlashCommand` command that was used"""
318318
def __init__(self, client, command, data, user, args = None, guild_ids = None, guild_permissions=None) -> None:
319319
SlashedCommand.__init__(self, client, command, data, user, args, guild_ids=guild_ids, guild_permissions=guild_permissions)
320-
SlashSubcommand.__init__(self, None, "EMPTY", "EMPTY")
320+
print(data)
321+
SlashSubcommand.__init__(self, None, ["EMPTY"], "EMPTY")
322+
self.base_names[0] = data["data"]["name"]
323+
_sub = data["data"]["options"][0]
324+
if _sub["type"] == OptionType.SUB_COMMAND_GROUP:
325+
print("group")
326+
self.base_names.append(_sub["name"])
327+
self.name = _sub["options"][0]["name"]
328+
else:
329+
print("sub")
330+
self.name = _sub["name"]
331+
321332

322333
class SlashedContext(Interaction, ContextCommand):
323334
def __init__(self, client, command: ContextCommand, data, user, param, guild_ids = None, guild_permissions = None) -> None:

0 commit comments

Comments
 (0)