【问题标题】:Discord.py warn commandDiscord.py 警告命令
【发布时间】:2021-01-31 05:37:34
【问题描述】:

我正在尝试使用 discord.py 创建警告命令。但是出于证明和原因,我在字符串参数方面遇到了麻烦。我试过用谷歌搜索这个问题,但找不到解决方案,比如使用 .format 或 .startswith。有没有人可以解决这个问题?

错误: discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: warn() missing 1 required keyword-only argument: 'proof'

使用的代码:

async def warn(context,member: discord.Member,*,reason:str,proof:str):
    tests = collection.find({"name":"test"})
    for test in tests:
        extract = (test["id"])
    extract += 1
    collection.update_one(update={"$set": {"id":extract}},filter={})
    print(extract)
    print(member.name)
    warnings = {"id": extract, "member": member.name, "reason": reason, "type": "warn", "proof":proof}
    collection.insert_one(warnings)

    await context.send(f"Succesfully warned {member.name} for {reason}")
    await member.send(f"You were warned in Mega Studios for {reason}")```

【问题讨论】:

    标签: python parameters discord discord.py discord.py-rewrite


    【解决方案1】:

    该错误基本上意味着您的遗忘证明!它 discord.py 需要 ctx 命令所需的所有变量!尝试使用 ALL 运行命令,例如: !warn @user <reason> <proof>

    注意:确保用 ctx 替换 Context 要容易得多!

    【讨论】:

      【解决方案2】:

      如果你想让proof 成为可选参数,你应该考虑这样做 async def warn(context,member: discord.Member,*,reason:str,proof:str="No reason"): .这将做的是,如果没有给出参数proof,则将proof 设置为No reason

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-03-04
        • 2020-03-31
        • 2021-10-20
        • 2021-05-05
        • 1970-01-01
        • 1970-01-01
        • 2022-12-10
        • 2021-07-25
        相关资源
        最近更新 更多