Discord.py 警告命令

时间:2021-01-31 05:37:34

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

我正在尝试使用 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}")```

1 个答案:

答案 0 :(得分:0)

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

注意:确保用 ctx 替换 Context 更容易!