【问题标题】:RuntimeWarning: coroutine 'update_bank' was never awaited ret = await coro(*args, **kwargs) RuntimeWarning: Enable tracemallocRuntimeWarning:从未等待协程“update_bank” ret = await coro(*args, **kwargs) RuntimeWarning:启用 tracemalloc
【发布时间】:2021-11-24 18:56:24
【问题描述】:

我不知道我做错了什么来得到这个错误......因为我已经等待了应该等待的事情,除非我没有而且我似乎看不到它?虽然说在我还没用的时候就在更新银行功能上,而且这个错误只有在使用这个命令的时候才会出现。

代码如下:

async def use_this(user,item_name,amount,price = None):
    item_name = item_name.lower()
    name_ = None
    for item in mainshop:
        name = item["name"].lower()
        if name == item_name:
            name_ = name
            if price==None:
                price = 0* item["price"]
            break

    if name_ == None:
        return [False,1]

    cost = price*amount

    users = await get_bank_data()

    bal = await update_bank(user)


    try:
        index = 0
        t = None
        for thing in users[str(user.id)]["bag"]:
            n = thing["item"]
            if n == item_name:
                old_amt = thing["amount"]
                new_amt = old_amt - amount
                if new_amt < 0:
                    return [False,2]
                users[str(user.id)]["bag"][index]["amount"] = new_amt
                t = 1
                break
            index+=1 
        if t == None:
            return [False,3]
    except:
        return [False,3]    

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

    await update_bank(user,cost,"wallet")

    return [True,"Worked"]


@client.command()
async def hunt(ctx,item = ['rifle','Rifle'],amount = 1):
    user = ctx.author
    users = await get_bank_data()
    res = await use_this(ctx.author,item,amount)

     
    rifle = "rifle"
    if amount > 1:
        await ctx.reply("You cant use multiple rifles,it would be too heavy for you!")
    elif item == "rifle":
        res = await use_this(ctx.author,item,amount)
    if not res[0]:
        if res[1]==1:
            await ctx.reply(f"{ctx.author.mention} That Object isn't there!")
            return
        if res[1]==2:
            await ctx.reply(f"{ctx.author.mention} You don't have {amount} {item} in your bag.")
            return
        if res[1]==3:
            await ctx.reply(f"{ctx.author.mention} You don't have {item} in your bag.")
            return
        aninames = ['bear','rabbit','wolf']
        animals = random.choice(aninames)
        earnings = random.randrange(5000)
        await ctx.reply(f"You used hunted {animals} for {earnings} coins!,you lost the rifle in the process tho ..")```

【问题讨论】:

  • 能否请您发布完整的回溯?

标签: python discord discord.py


【解决方案1】:

试着去做

import tracemalloc

tracemalloc.start()

那么你应该得到完整的回溯 这样更容易为您提供帮助

【讨论】:

    【解决方案2】:

    您需要将await 添加到update_bank

    那就去做吧:

    await update_bank(...)
    

    注意:把需要的东西,比如 ctx.author 放进去。

    当你看到这个

    update_bank(...)
    

    【讨论】:

    • 到处都在等待……
    猜你喜欢
    • 1970-01-01
    • 2018-10-26
    • 2021-10-22
    • 2019-12-15
    • 2021-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-10
    相关资源
    最近更新 更多