问题出在 await open_account(ctx.author)
线上。当我不和谐地执行命令时,它会输出 4-5 次相同的响应,但它按预期运行。回到提示中,它突出显示了我之前提到的那一行。对于此代码中的任何其他客户端命令,也会发生这种情况。任何想法如何解决它?非常感谢。
@client.command()
async def balance(ctx):
await open_account(ctx.author)
user = ctx.author
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")
em.add_field(name = "Wallet balance", value = wallet_amt)
em.add_field(name = "Bank balance", value = bank_amt)
await ctx.send(embed = em)
答案 0 :(得分:0)
您的代码看起来不错。但是,您可以尝试在代码末尾内置 return
。如果机器人多次发送命令输出,您可能同时运行多个实例。
@client.command()
async def balance(ctx):
await open_account(ctx.author)
user = ctx.author
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")
em.add_field(name = "Wallet balance", value = wallet_amt)
em.add_field(name = "Bank balance", value = bank_amt)
await ctx.send(embed = em)
return # Prevents the bot from sending more