因此,我正在努力做到这一点,以便主持人可以将用户注册到我们存储货币的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.")```
答案 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的更多信息。