pycord
pycord copied to clipboard
ext.bridge improvements
Summary
Makes a bunch of changes to ext.bridge
- Implements bridge command groups
-
bridge.map_to
decorator to use main command as subcommand
-
- Attachment option
-
is_app
property added to better differentiate context types
Information
- [x] This PR fixes an issue.
- [x] This PR adds something new (e.g. new method or parameters).
- [ ] This PR is a breaking change (e.g. methods or parameters removed/renamed).
- [ ] This PR is not a code change (e.g. documentation, README, typehinting, examples, ...).
Checklist
- [x] I have searched the open pull requests for duplicates.
- [x] If code changes were made then they have been tested.
- [x] I have updated the documentation to reflect the changes.
- [ ] If
type: ignore
comments were used, a comment is also left explaining why.
@Dorukyum
I'm facing two issues. The code I used for testing:
bot = bridge.Bot(command_prefix="t.", intents=Intents.all())
@bot.bridge_group(description="Test command")
async def hello(ctx: bridge.BridgeContext, attachment: Attachment):
await ctx.respond(attachment.filename)
- The slash command doesn't have any options
- I get the following exception even though I have attached a file:
Ignoring exception in command hello:
Traceback (most recent call last):
File "/home/dorukyum/Desktop/Code/pycord/discord/ext/commands/bot.py", line 344, in invoke
await ctx.command.invoke(ctx)
File "/home/dorukyum/Desktop/Code/pycord/discord/ext/commands/core.py", line 1532, in invoke
await self.prepare(ctx)
File "/home/dorukyum/Desktop/Code/pycord/discord/ext/commands/core.py", line 873, in prepare
await self._parse_arguments(ctx)
File "/home/dorukyum/Desktop/Code/pycord/discord/ext/commands/core.py", line 779, in _parse_arguments
transformed = await self.transform(ctx, param)
File "/home/dorukyum/Desktop/Code/pycord/discord/ext/commands/core.py", line 612, in transform
raise MissingRequiredArgument(param)
discord.ext.commands.errors.MissingRequiredArgument: attachment is a required argument that is missing.
Probably fixed now. I just made it so that slash groups without subcommands are not registered since the library in general doesn't support slash groups with callbacks.
Pain
Hahahahaha
I won't approve this tho
Could we add an example?
I get the following error on startup now:
Traceback (most recent call last):
File "test.py", line 9, in <module>
async def hello(ctx: bridge.BridgeContext):
File "discord/ext/bridge/bot.py", line 88, in decorator
result = bridge_group(**kwargs)(func)
File "discord/ext/bridge/core.py", line 318, in decorator
return BridgeCommandGroup(callback, **kwargs)
File "discord/ext/bridge/core.py", line 262, in __init__
self.slash_variant: BridgeSlashGroup = BridgeSlashGroup(self.ext_variant.name, *args, **kwargs)
File "discord/ext/bridge/core.py", line 64, in __init__
super().__init__(func, **kwargs)
File "discord/commands/core.py", line 625, in __init__
raise TypeError("Callback must be a coroutine.")
TypeError: Callback must be a coroutine.
The code I used:
bot = bridge.Bot(command_prefix="t.", intents=Intents.all())
@bot.bridge_group(description="Test command")
async def hello(ctx: bridge.BridgeContext):
...
@hello.command()
async def there(ctx: bridge.BridgeContext, attachment: Attachment):
await ctx.respond(attachment.filename)