我有一个重写版本 discord.py.如果消息有内容,则不会发生错误.我需要如果消息没有内容,则不会发生错误.
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.
我的代码:
@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)
完整的追溯:
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.
命令解析参数的方式意味着定义
The way commands parse arguments means that defining
async def search(ctx, message):
意味着 search 需要一个词 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)
此功能记录在此处一个>.
这篇关于Discord.py 缺少必需的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
python:不同包下同名的两个模块和类python: Two modules and classes with the same name under different packages(python:不同包下同名的两个模块和类)
配置 Python 以使用站点包的其他位置Configuring Python to use additional locations for site-packages(配置 Python 以使用站点包的其他位置)
如何在不重复导入顶级名称的情况下构造python包How to structure python packages without repeating top level name for import(如何在不重复导入顶级名称的情况下构造python包)
在 OpenShift 上安装 python 包Install python packages on OpenShift(在 OpenShift 上安装 python 包)
如何刷新 sys.path?How to refresh sys.path?(如何刷新 sys.path?)
分发带有已编译动态共享库的 Python 包Distribute a Python package with a compiled dynamic shared library(分发带有已编译动态共享库的 Python 包)