当我尝试使用(member.id)时,收到一个错误代码



我当前的代码是

@client.command()
async def check_vouches(ctx, member : discord.User=None):
users = await get_vouch_data()
test = ctx.author
role = discord.utils.get(test.guild.roles, name="10 vouches")
vouches_gotten = users[str(member.id)]["vouches_gotten"]

if member is not None:
if vouches_gotten == 10:

await test.add_roles(role)
await ctx.send("you now have the {role} role")
else:
await ctx.reply("first get 10 vouches")

当我启动机器人时,它不会给出错误代码,但当我尝试使用命令时,我会得到以下错误代码:

Ignoring exception in command check_vouches:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "main.py", line 193, in check_vouches
vouches_gotten = users[str(member.id)]["vouches_gotten"]
AttributeError: 'NoneType' object has no attribute 'id'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'id'

我已经试过放了

async def check_vouches(ctx, member : discord.User=None,*, id):

但当我尝试使用身份证时,仍然没有成功。请帮助我,因为我没有主意,因为我已经尝试编辑了一些东西,但它仍然给了我一个错误代码

正如注释中所说,只有当成员为None时,才继续操作,而事实并非如此。如果成员为None,则可以执行两件事:为其指定默认值,然后继续或停止命令并引发错误。

停止命令:

if member is None:
await ctx.send('You have to mention someone to check their vouches')
else:
# check and show vouch

提供默认值:(作者(

if member is None:
member = ctx.author
# don't check if member is None later
#check and show vouches

相关内容

最新更新