They are called keyword-only arguments. They restrict all the parameters that come after the *
to accept keyword-only arguments.
With your given example:
@commands.command()
async def avatar(self, ctx, *, avamember : discord.Member=None):
userAvatarUrl = avamember.avatar_url
await ctx.send(userAvatarUrl)
If you invoke the avatar
function with positional arguments only:
avatar(ctx_value, "member_value")
It will throw an error. TypeError: avatar() takes 1 positional argument but 2 were given
.
The function will only accept a positional argument as the first argument, and a keyword-only argument as a second argument. To avoid the error, you must invoke the avatar
function with a keyword-only argument as a second argument:
avatar(ctx_value, avamember="member_value")
Note. Am using strings for "member_value" because I don't know the discord.Member
type hint. So you must replace it with the appropriate type.