首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Discord.py经济命令

Discord.py经济命令
EN

Stack Overflow用户
提问于 2020-08-04 10:41:33
回答 5查看 4.3K关注 0票数 0

我正在为我的机器人做一个经济命令。我认为错误出在open_account()函数中。当您运行balance命令时,它看到我没有帐户,并按应该的方式写入JSON文件,但没有发送嵌入内容。我检查了嵌入器,它工作正常。这是在调用embed之前的事情。此外,beg命令不会将您创建的数量添加到JSON文件中。我花了几天的时间试图理解问题是什么,但没有运气。有人能帮我找出我哪里搞砸了吗?

代码语言:javascript
复制
@client.command()
async def balance(ctx):await open_account(ctx.author)

    users = await get_bank_data()


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

    embed=discord.Embed(title="{}s balance:".format(member.name), color=0xe20303)
    embed.add_field(name="Wallet:", value=wallet_amt, inline=False)
    embed.add_field(name="Bank:", value=bank_amt, inline=False)

    await ctx.send(embed=embed)

async def open_account(user):
    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("bank.json", "w") as f:
        json.dump(users, f)
    return True

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


@client.command()
async def beg(ctx):

    users = await get_bank_data()
    user = ctx.author
    earnings = random.randrange(2000)

    if earnings == 0:
        await ctx.send(f"How unlucky... You didn't get anything...")

    elif earnings > 50:
        await ctx.send(f"Nice you got ${earnings} from a cool dude")

    elif earnings > 100:
        await ctx.send(f"Someone felt nice and gave you ${earnings}")

    elif earnings > 500:
        await ctx.send(f"You seem to have a way with people! Someone gave you ${earnings}")

    elif earnings > 800:
        await ctx.send(f"What a lucky day!! Someone gave you ${earnings}")

    elif earnings > 1500:
        await ctx.send(f"A rich man passed by you and felt bad. So ha gave you ${earnings}")

    elif earnings > 2000:
        await ctx.send(f"A shady man walked up to you and said 'I know how tough it can be out here' before giving you ${earnings}")


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

    with open("bank.json", "r") as f:
        users = json.load(f)
EN

回答 5

Stack Overflow用户

发布于 2020-08-04 18:19:49

函数open_account和get_bank_data不是异步函数。尝试删除它们之前的异步/等待。

票数 0
EN

Stack Overflow用户

发布于 2020-10-31 18:39:22

此外,在开始时,尝试将async def balance(ctx):await open_account(ctx.author)间隔等待open_account应该在不同的行上。

票数 0
EN

Stack Overflow用户

发布于 2020-11-29 14:33:25

在倒数第三行中,您将str错误地拼写为srt

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63239496

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档