Skip to content

Commit ea0fa3a

Browse files
committed
Update docs and prepare for launch.
1 parent 296f36f commit ea0fa3a

File tree

4 files changed

+51
-29
lines changed

4 files changed

+51
-29
lines changed

discord_slash/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ async def to_dict(self):
308308
"options": selected.options or [],
309309
"default_permission": selected.default_permission,
310310
"permissions": selected.permissions or {},
311-
"type": selected.type,
311+
"type": selected._type,
312312
}
313313
wait["global"][x] = copy.deepcopy(command_dict)
314314

@@ -1022,7 +1022,7 @@ def wrapper(cmd):
10221022

10231023
return wrapper
10241024

1025-
def context_menu(self, target: int, name: str, guild_ids: list = None):
1025+
def context_menu(self, *, target: int, name: str, guild_ids: list = None):
10261026
"""
10271027
Decorator that adds context menu commands.
10281028

discord_slash/cog_ext.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def wrapper(cmd):
192192
# I don't feel comfortable with having these right now, they're too buggy even when they were working.
193193

194194

195-
def cog_context_menu(name: str, guild_ids: list = None, target: int = 1):
195+
def cog_context_menu(*, name: str, guild_ids: list = None, target: int = 1):
196196
"""
197197
Decorator that adds context menu commands.
198198

discord_slash/context.py

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -638,13 +638,11 @@ class MenuContext(InteractionContext):
638638
"""
639639
Context of a context menu interaction. Has all attributes from :class:`InteractionContext`, plus the context-specific ones below.
640640
641-
:ivar target_id: The target ID of the context menu command.
642641
:ivar context_type: The type of context menu command.
643-
:ivar menu_messages: Dictionary of messages collected from the context menu command. Defaults to ``None``.
644-
:ivar menu_authors: Dictionary of users collected from the context menu command. Defaults to ``None``.
645-
:ivar context_message: The message of the context menu command if present. Defaults to ``None``.
646-
:ivar context_author: The author of the context menu command if present. Defaults to ``None``.
647642
:ivar _resolved: The data set for the context menu.
643+
:ivar target_message: The targeted message of the context menu command if present. Defaults to ``None``.
644+
:ivar target_id: The target ID of the context menu command.
645+
:ivar target_author: The author targeted from the context menu command.
648646
"""
649647

650648
def __init__(
@@ -657,33 +655,37 @@ def __init__(
657655
super().__init__(_http=_http, _json=_json, _discord=_discord, logger=logger)
658656
self.context_type = _json["type"]
659657
self._resolved = self.data["resolved"] if "resolved" in self.data.keys() else None
660-
self.target = {"id": self.data["target_id"], "message": None}
658+
self.target_message = None
659+
self.target_author = None
660+
self.target_id = self.data["target_id"]
661661

662662
if self._resolved is not None:
663-
if self.context_type in [3, "3"]:
664-
self.target["message"] = model.SlashMessage(
665-
state=self.bot._connection,
666-
channel=_discord.get_channel(self.channel_id),
667-
data=[msg for msg in self._resolved["messages"]][0],
668-
_http=_http,
669-
interaction_token=self._token,
670-
)
671-
672663
try:
673-
if self.guild and self._resolved["members"]:
674-
_member = True
675-
self.target["author"] = discord.Member(
676-
data=[auth for auth in self._resolved["members"]][0],
664+
if self._resolved["messages"]:
665+
_msg = [msg for msg in self._resolved["messages"]][0]
666+
self.target_message = model.SlashMessage(
677667
state=self.bot._connection,
678-
guild=self.guild
668+
channel=_discord.get_channel(self.channel_id),
669+
data=self._resolved["messages"][_msg],
670+
_http=_http,
671+
interaction_token=self._token,
679672
)
680673
except KeyError: # noqa
681674
pass
675+
682676
try:
683-
if self._resolved["users"]:
684-
self.target["author"] = discord.User(
685-
data=[auth for auth in self._resolved["users"]][0],
686-
state=self.bot_connection
677+
if self.guild and self._resolved["members"]:
678+
_auth = [auth for auth in self._resolved["members"]][0]
679+
self.target_author = discord.Member(
680+
data=self._resolved["members"][_auth],
681+
state=self.bot._connection,
682+
guild=self.guild
683+
)
684+
else:
685+
_auth = [auth for auth in self._resolved["users"]][0]
686+
self.target_author = discord.User(
687+
data=self._resolved["users"][_auth],
688+
state=self.bot._connection
687689
)
688690
except KeyError: # noqa
689691
pass

docs/gettingstarted.rst

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,21 +358,41 @@ Unlike `manage_commands` and `manage_components`, you will have to use a decorat
358358

359359
.. code-block :: python
360360
361+
from discord_slash.context import MenuContext
361362
from discord_slash.model import ContextMenuType
362363
363-
@slash.context_menu(ContextMenuType.MESSAGE,
364+
@slash.context_menu(target=ContextMenuType.MESSAGE,
364365
name="commandname",
365366
guild_ids=[789032594456576001])
366367
async def commandname(ctx: MenuContext):
367368
await ctx.send(
368-
content="Responded!",
369+
content=f"Responded! The content of the message targeted: {ctx.target_message.content}",
369370
hidden=True
370371
)
371372
372373
The `@slash.context_menu` decorator takes in the context type as given (to either appear when you right-click on a user or when you right-click on a message) as well
373374
as the name of the command, and any guild IDs if given if you would like to make it applicable to only a guild. **We only accept connected names** for the time being,
374375
although context menus will have the ability to have spaces in their name in the future when development further progresses.
375376

377+
You are able to also use the `@cog_ext.cog_context_menu` path which will require an import from `cog_ext.py` respectively, however, it is worth nothing that
378+
the `target` kwarg for the decorator **must** be brought to the very end.
379+
380+
Can I use components with context menus?
381+
----------------------------------------
382+
Of course! However, you will need to add in some additional code in order for both of the separate contexts to work seamlessly. Below is the given code of what will need
383+
to be changed:
384+
385+
.. code-block :: python
386+
387+
from discord_slash.context import ComponentContext, MenuContext
388+
from discord_slash.model import ContextMenuType
389+
from typing import Union
390+
391+
...
392+
393+
async def my_new_command(ctx: Union[ComponentContext, MenuContext]):
394+
...
395+
376396
Hey, what about component/[X] listening?
377397
----------------------------------------
378398
The decision has been made that this will not be implemented because of two reasons: context menus currently have no ability to hold any options or choices, so listening

0 commit comments

Comments
 (0)