AttributeError:“消息”对象没有属性“成员”-Discord.py Rewrite

时间:2020-07-23 17:57:47

标签: python discord.py

因此,我正在努力做到这一点,以便主持人可以将用户注册到我们存储货币的JSON文件中。

这是我的代码,出现错误:

id = str(ctx.message.member.id)
AttributeError: 'Message' object has no attribute 'member'
@bot.command(pass_context=True)
async def registeruser(ctx, member: discord.Member):
    id = str(ctx.message.member.id)
    if id not in amounts:
        amounts[id] = 0
        await ctx.send("You are now registered to AccoladeBot.")
        _save()
    else:
        await ctx.send("You already have an account.")```

1 个答案:

答案 0 :(得分:1)

如果要检查指定的用户是否有帐户,则应写str(member.id)而不是str(ctx.message.member.id)

@bot.command()
async def registeruser(ctx, member: discord.Member):
    id = str(member.id)
    if id not in amounts:
        amounts[id] = 0
        await ctx.send("You are now registered to AccoladeBot.")
        _save()
    else:
        await ctx.send("You already have an account.")

有关Context对象here的更多信息。