Skip to content

Inconsistent default arguments in bridge commands #2089

Description

@solaluset

Summary

Bridge commands do not always handle default arguments in the same way

Reproduction Steps

  1. Create a bridge command with non-required argument (via Option kwargs)
  2. Try to run it without the argument in question

Minimal Reproducible Code

import os

import discord
from discord.ext import bridge
# Option MUST be imported after ext.bridge
# otherwise it won't work with bridge commands
from discord import Option


bot = bridge.Bot()


@bot.bridge_command()
async def test_default1(ctx, text: Option(str) = "hello"):
    await ctx.respond(text)


@bot.bridge_command()
async def test_default2(ctx, text: Option(str, default="hello")):
    await ctx.respond(text)


@bot.bridge_command()
async def test_no_default(ctx, text: Option(str, required=False)):
    await ctx.respond(text or "hello")


bot.run(os.getenv("TOKEN"))

Expected Results

I'd expect all three commands from the above code to produce the same output when the argument isn't provided, like it does for slash variants:
Screenshot_20230528-133333989 (1)

Actual Results

However, only the first one works:
Screenshot_20230528-133607047 (1)
Others are throwing an error:

Traceback (most recent call last):
  File "/data/data/com.termux/files/home/tests/lib/python3.11/site-packages/discord/ext/bridge/bot.py", line 143, in invoke
    await ctx.command.invoke(ctx)
  File "/data/data/com.termux/files/home/tests/lib/python3.11/site-packages/discord/ext/commands/core.py", line 942, in invoke
    await self.prepare(ctx)
  File "/data/data/com.termux/files/home/tests/lib/python3.11/site-packages/discord/ext/commands/core.py", line 872, in prepare
    await self._parse_arguments(ctx)
  File "/data/data/com.termux/files/home/tests/lib/python3.11/site-packages/discord/ext/commands/core.py", line 774, in _parse_arguments
    transformed = await self.transform(ctx, param)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/home/tests/lib/python3.11/site-packages/discord/ext/bridge/core.py", line 105, in transform
    return await super().transform(ctx, param)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/home/tests/lib/python3.11/site-packages/discord/ext/commands/core.py", line 601, in transform
    raise MissingRequiredArgument(param)
discord.ext.commands.errors.MissingRequiredArgument: text is a required argument that is missing.

Intents

None

System Information

  • Python v3.11.2-final
  • py-cord v2.4.1-final
  • aiohttp v3.8.4
  • system info: Linux 4.14.232-QuicksilveR™-ReloadedOS-Edition #1 SMP PREEMPT Wed May 26 07:08:17 UTC 2021

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

Additional Context

Not related to this particular issue, but I don't quite like how Option works with bridge commands. Relying on the order of imports is something very non-obvious, confusing and, iirc, not documented.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingext.bridgeRelating to ext.bridgeon hold

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions