Skip to content

Slash command member Option does not return user ID for external users when the option is optional #446

Closed
@SlimShadyIAm

Description

@SlimShadyIAm

Summary

When you use discord.Member as the type of an Option and you pass in the ID of someone not in the guild when invoking, the argument is parsed to the ID of the user (which is expected). You can then fetch this ID using Client.fetch_user to get the User object. But when the member option is optional (required=False), the argument is parsed to to None instead of the ID even when a valid ID is passed in.

Reproduction Steps

  1. Make a command with a discord.Member option
  2. Try to execute the command when the option has required=True with the ID of someone not in the server (e.g /cases user:386131861107376128)
  3. Print the parameter and you will see the ID
  4. Now set required=False, run the command and print the ID again
  5. You will see that this time, None is printed instead of the ID. So you cannot have the argument as optional.

Minimal Reproducible Code

@slash_command(guild_ids=[123], description="Show your or another user's cases")
async def cases(self, ctx, user: Option(discord.Member, description="Member to show cases of", required=False)):
    print(user)

Expected Results

The command argument parser returns the ID of the user.

Actual Results

The command argument parser returns None instead of the ID.

Intents

Default + members, messages, presences

System Information

  • Python v3.10.0-final
  • py-cord v2.0.0-alpha
    • py-cord pkg_resources: v2.0.0a4406+g4d8b3d93
  • aiohttp v3.7.4.post0
  • system info: Linux 5.10.47-linuxkit Update README.rst #1 SMP PREEMPT Sat Jul 3 21:50:16 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

The use case for this is, for example, a user info command where you want to be able to display info of:

  • users in the server
  • users outside the server
  • but make the user argument optional so it defaults to the command invoker

Metadata

Metadata

Assignees

No one assigned

    Labels

    unconfirmed bugA bug report that needs triaging

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions