Skip to content

Commit 8c1bec6

Browse files
authored
Merge branch 'master' into master
2 parents c7aeb26 + b05b083 commit 8c1bec6

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

discord/bot.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@
6464
CoroFunc = Callable[..., Coroutine[Any, Any, Any]]
6565
CFT = TypeVar('CFT', bound=CoroFunc)
6666

67+
__all__ = (
68+
'ApplicationCommandMixin',
69+
'Bot',
70+
'AutoShardedBot',
71+
)
72+
6773
class ApplicationCommandMixin:
6874
"""A mixin that implements common functionality for classes that need
6975
application command compatibility.

discord/commands/commands.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,11 +543,15 @@ async def invoke_autocomplete_callback(self, interaction: Interaction):
543543
for i in interaction.data["options"]
544544
})
545545
ctx = AutocompleteContext(interaction, command=self, focused=option, value=op.get("value"), options=values)
546-
result = await option.autocomplete(ctx)
546+
if asyncio.iscoroutinefunction(option.autocomplete):
547+
result = await option.autocomplete(ctx)
548+
else:
549+
result = option.autocomplete(ctx)
550+
547551
choices = [
548552
o if isinstance(o, OptionChoice) else OptionChoice(o)
549553
for o in result
550-
]
554+
][:25]
551555
return await interaction.response.send_autocomplete_result(choices=choices)
552556

553557

@@ -648,7 +652,7 @@ def __init__(
648652
not asyncio.iscoroutinefunction(self.autocomplete)
649653
):
650654
raise TypeError("Autocomplete callback must be a coroutine.")
651-
655+
652656
def to_dict(self) -> Dict:
653657
as_dict = {
654658
"name": self.name,

discord/commands/context.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
if TYPE_CHECKING:
3232
import discord
33+
from discord import Bot
3334
from discord.state import ConnectionState
3435

3536
from .commands import ApplicationCommand, Option
@@ -65,7 +66,7 @@ class ApplicationContext(discord.abc.Messageable):
6566
The command that this context belongs to.
6667
"""
6768

68-
def __init__(self, bot: "discord.Bot", interaction: Interaction):
69+
def __init__(self, bot: Bot, interaction: Interaction):
6970
self.bot = bot
7071
self.interaction = interaction
7172
self.command: ApplicationCommand = None # type: ignore
@@ -174,3 +175,11 @@ def __init__(self, interaction: Interaction, *, command: ApplicationCommand, foc
174175
self.focused = focused
175176
self.value = value
176177
self.options = options
178+
179+
@property
180+
def cog(self) -> Optional[Cog]:
181+
"""Optional[:class:`.Cog`]: Returns the cog associated with this context's command. None if it does not exist."""
182+
if self.command is None:
183+
return None
184+
185+
return self.command.cog

0 commit comments

Comments
 (0)