python 错误:命令引发异常:属性错误:“Message”对象没有属性“member”

llycmphe  于 2023-05-21  发布在  Python
关注(0)|答案(2)|浏览(206)

我正在尝试使用discord.py将货币命令添加到我的Discord机器人。这是我的代码:

@client.command()
async def balance(ctx):
    await open_account(ctx.message.member)
    user = ctx.message.member
    users = await get_bank_data()

    wallet_amt = users[str(user.id)]["wallet"]
    bank_amt = users[str(user.id)]["bank"]

    em = discord.Embed(title=f"{ctx.author.name}'s balance",
                       color=discord.Color.red())
    em.add.field(name="Wallet balance", value=wallet_amt)
    em.add.field(name="Bank balance", value=bank_amt)
    await ctx.send(embed=em)


@client.command()
async def beg(ctx):
    await open_account(ctx.message.member, )

    users = await get_bank_data()

    user = ctx.message.member

    earnings = random.randrange(101)

    await ctx.send(f"Someone gave you {earnings}coins!!")

    users[str(user.id)]["wallet"] += earnings

    with open("mainbank.json", "w") as f:
        json.dump(users, f)

async def open_account(ctx):
    user = ctx.message.member
    users = await get_bank_data()
    if str(user.id) in users:
        return False
    else:
        users[str(user.id)] = {}
    users[str(user.id)]["wallet"] = 0
    users[str(user.id)]["bank"] = 0

    with open("mainbank.json", "w") as f:
        json.dump(users, f)
    return True

async def get_bank_data():
    with open("mainbank.json", "r") as f:
        users = json.load(f)
        return users

但是当我使用balance命令时,我得到了这个错误:
错误:命令引发异常:属性错误:“Message”对象没有属性“member”

5uzkadbs

5uzkadbs1#

这是因为您需要使用ctx.author来获取消息作者。

nfs0ujit

nfs0ujit2#

这是因为www.example.com中的message对象discord.py没有member属性。因此,您需要使用message.author

相关问题