【问题标题】:I am creating a Discord bot, and there was a need to create slash commands. Several commands work, but all the others give a TypeError我正在创建一个 Discord 机器人,并且需要创建斜杠命令。几个命令有效,但所有其他命令都给出 TypeError
【发布时间】:2022-08-21 21:36:47
【问题描述】:
@slash.slash(name=\'info\', description=\'information\',
             options=[{\"name\": \"category\", \"description\": \"category info\", \"type\": 3, \"required\": True}])
@bot.command()
async def info(ctx, categoty: str = None):
    print(categoty)
    match categoty:
        case \'commands\':
            await ctx.send(f\"```{categoty}:\\
            \\n    {setting[\'prefix\']}hello\\
            \\n    {setting[\'prefix\']}top\\
            \\n    {setting[\'prefix\']}avatar\\
            \\n    {setting[\'prefix\']}balance\\
            \\n    {setting[\'prefix\']}reward\\
            \\n    {setting[\'prefix\']}take```\")
        case \'help\':
            await ctx.send(\"```information```\")
        case None:
            await ctx.send(f\"```info:\\
            \\n    {setting[\'prefix\']}info commands\\
            \\n    {setting[\'prefix\']}info help```\")
        case _:
            await ctx.send(\"```commands not found```\")

如果通过前缀调用函数本身可以正常工作,但如果通过斜杠调用,则会出现此错误。

An exception has occurred while executing command `info`:
Traceback (most recent call last):
  File \"/Users/bogdan/PycharmProjects/discord-bot/venv/lib/python3.10/site-packages/discord_slash/client.py\", line 1353, in invoke_command
    await func.invoke(ctx, **args)
  File \"/Users/bogdan/PycharmProjects/discord-bot/venv/lib/python3.10/site-packages/discord_slash/model.py\", line 210, in invoke
    return await self.func(*args, **kwargs)
  File \"/Users/bogdan/PycharmProjects/discord-bot/venv/lib/python3.10/site-packages/discord/ext/commands/core.py\", line 374, in __call__
    return await self.callback(*args, **kwargs)
TypeError: info() got an unexpected keyword argument \'category\'
  • 请将代码和错误作为文本而不是图像发布。
  • 我按照你的要求做了

标签: python discord.py


【解决方案1】:

您拼错了类别,并且在斜杠命令选项中您的拼写正确 - 因此代码提供了错误的关键字参数。

【讨论】:

    猜你喜欢
    • 2022-10-07
    • 2021-10-06
    • 2014-07-25
    • 2023-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-04
    相关资源
    最近更新 更多