Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

python - Discord.py missing required argument

I have a rewrite version discord.py.If message have content, error does not happened.I need that error does not happened if message have not content.

My code:

    @client.command(pass_context = True)
    def async search(ctx,message):
    ...
    some code 
    ...
         if members_count < voice_channel.user_limit:
                        message.content += ' '
                        print(message.content)

                        invite = await channel.create_invite(max_age=0)
                        avatar = user.avatar_url
                        if message == '':
                            message_for_emb = 'u200b'
                        elif message != '':
                            message_for_emb = ':white_small_square: {}'.format(message)
                        if user.default_avatar_url == avatar:
                            avatar = 'https://i.imgur.com/XjeDXnB.png'
                        embed = discord.Embed(description=members, colour=discord.Embed.Empty)
                        embed.set_author(name='В поисках +{} в {}  {}'.format((voice_channel.user_limit - members_count),
                                                                          voice_channel.category.name,voice_channel.name), icon_url=avatar)
                        embed.add_field(name=message_for_emb,
                                        value='Зайти: {} :white_check_mark:'.format(invite.url), inline=False)
                        await channel.send(embed=embed)

Full traceback:

Ignoring exception in command search:
Traceback (most recent call last):
  File "C:UsersДаниилPycharmProjectsdiscordbotvenvlibsite-packagesdiscordextcommandsot.py", line 886, in invoke
    yield from ctx.command.invoke(ctx)
  File "C:UsersДаниилPycharmProjectsdiscordbotvenvlibsite-packagesdiscordextcommandscore.py", line 491, in invoke
    yield from self.prepare(ctx)
  File "C:UsersДаниилPycharmProjectsdiscordbotvenvlibsite-packagesdiscordextcommandscore.py", line 455, in prepare
    yield from self._parse_arguments(ctx)
  File "C:UsersДаниилPycharmProjectsdiscordbotvenvlibsite-packagesdiscordextcommandscore.py", line 369, in _parse_arguments
    transformed = yield from self.transform(ctx, param)
  File "C:UsersДаниилPycharmProjectsdiscordbotvenvlibsite-packagesdiscordextcommandscore.py", line 249, in transform
    raise MissingRequiredArgument(param)
discord.ext.commands.errors.MissingRequiredArgument: message is a required argument that is missing.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The way commands parse arguments means that defining

async def search(ctx, message):

means that search requires a word message as part of the command invocation. If you instead want to capture the remainder of the message, you can use the keyword-only argument syntax:

async def search(ctx, *, message)

This feature is documented here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...