feat: allow passing autocompleters that take a cog as first argument to commands.Param#1269
Conversation
|
This technically solves the original issue (ref); however, and correct me if i'm wrong, at least in that case, it just happens to work out as both cogs have a class Autocompleters(commands.Cog):
def __init__(self, bot) -> None:
self.bot: commands.Bot = bot
async def category(self, inter: disnake.CommandInteraction, query: str):
print(type(self)) # <<<<<
categories = ["things", "more", "stuff"]
return [c for c in categories if query.lower() in c]
class Misc(commands.Cog):
def __init__(self, bot) -> None:
self.bot: commands.Bot = bot
@commands.slash_command()
async def test(
self,
inter: disnake.GuildCommandInteraction,
cat: str = commands.Param(autocomplete=Autocompleters.category),
) -> None:
await inter.send(cat)The |
|
(EDIT: forgot the cog in the code example mmlol) Absolutely valid concern. I personally don't think "inter-cog" autocompleters really make sense either, but I could see a more top-level approach work fine: async def some_autocompleter(
self: commands.Cog, # Or a protocol
inter: disnake.CommandInteraction,
data: str,
):
# if need be can isinstance(self, ...) with a cog class or a protocol
return ...
class Misc(commands.Cog):
@commands.slash_command()
async def test(
self,
inter: disnake.GuildCommandInteraction,
cat: str = commands.Param(autocomplete=some_autocompleter),
) -> None:
await inter.send(cat) |
Yea, fair point. In any case, I suppose adding the |
Summary
Currently,
commands.Paramassumes the provided autocompleter does not take a cog and is typehinted as such, despite somewhat working with alternative autocomplete options such as a simple sequence.This PR ensures cog-based autocompleters work with
commands.Param.The typehint is changed to work with any valid autocompleter (callback without cog, callback with cog, sequence), and callbacks are internally marked so that slash commands handle them correctly.
Checklist
pdm lintpdm pyright