【问题标题】:discord.ext.commands.errors.CommandNotFound: Command "balance" is not found error even though its therediscord.ext.commands.errors.CommandNotFound:命令“平衡”未找到错误,即使它在那里
【发布时间】:2020-12-19 21:58:01
【问题描述】:

我正在尝试制作一个带有经济系统的 discord.py 机器人,这是显示平衡的基本脚本。

client.command()
async def balance(ctx):
    global user

    await open(ctx.author)
    users = await get()

    wallet_data = users[str(user.id)]["wallet"]
    bank_data = users[str(user.id)]["bank"]

    details = discord.Embed(title=f"{ctx.author.name}'s balance now", color=discord.Color.red())
    details.add_field(name="W A L L E T", value=wallet_data)
    details.add_field(name="B A N K", value=bank_data)

    await ctx.send(embed=details)


async def open(user):
    global users

    users = await get()
    
    with open(r"C:\discbot\bank.json", "r") as data:
        users = json.load(data)
    
    if str(user.id) in users:
        return False
    
    else: 
        users[str(user.id)]["wallet"]=0
        users[str(user.id)]["bank"]=0
    
        with open(r"C:\discbot\bank.json", "w") as data:
            json.dump(users,data)
    
        return True


async def get():
    with open(r"C:\discbot\bank.json", "r") as data:
        users = json.load(data)

    return users


client.run(ID)

然而它会返回

discord.ext.commands.errors.CommandNotFound: Command "balance" is not found

虽然平衡是在我运行时定义的。

【问题讨论】:

  • 你能把@放在client.command()的开头吗?

标签: discord discord.py


【解决方案1】:

您需要在 async def ... 之前调用 @client.command() 以将其注册为命令。

@client.command()
async def foo(ctx):
    await ctx.send("bar")

另外,你重新定义了开放。所以你的async def open函数在调用时会递归,会报错。

【讨论】:

    猜你喜欢
    • 2021-09-12
    • 2023-02-25
    • 1970-01-01
    • 1970-01-01
    • 2021-02-19
    • 2014-08-01
    • 1970-01-01
    • 2012-08-13
    • 2013-07-29
    相关资源
    最近更新 更多