You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

discord.py新timeout函数报错:位置-only参数被当作关键字参数传递

修复discord.py超时命令的TypeError问题

你遇到的错误是因为member.timeout()方法中,until是位置-only参数,不能通过关键字参数的形式(until=xxx)传递。

修复后的代码:

@commands.command()
async def timeout(self, ctx, member: discord.Member, time, reason, /):
    # 直接将timedelta作为位置参数传递,无需指定until关键字
    await member.timeout(datetime.timedelta(seconds=int(time)), reason=reason)

补充说明:

  • 位置-only参数的设计要求必须按参数顺序位置传递,不能用关键字指定,这是discord.py新版本方法的参数规则。
  • 如果需要设置永久超时,可传递discord.utils.utcnow()作为参数,但临时超时场景下用timedelta更符合需求。

内容的提问来源于stack exchange,提问作者Inj3ct0r

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 13:06:27