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

discord.py报错:Interaction.delete_original_response缺少self参数,如何定时删消息?

问题解决:Discord斜杠命令删除响应消息报错

你遇到的TypeError是因为直接通过discord.Interaction类调用了delete_original_response方法,这个方法需要通过Interaction实例(也就是你的ctx参数)来调用,而不是类本身。

下面是两种可行的修复方案:

方法1:通过ctx实例调用删除方法

把单独的删除语句改成用ctx调用:

@bot.slash_command(name="clearall", description="Clears all Messages")
@commands.has_permissions(manage_messages = True)
async def clearall(ctx):
    await ctx.channel.purge()
    await ctx.respond("Done!")
    # 直接用ctx调用delete_original_response
    await ctx.delete_original_response(delay=5)

@clearall.error
async def clearerror(ctx, error):
    if isinstance(error, MissingPermissions):
        await ctx.respond("Do you have manage message permissions?")
    else:
        raise error

方法2:直接在respond时设置自动删除(更简洁)

不需要单独调用删除方法,在respond里添加delete_after参数,让消息自动在指定时间后删除:

@bot.slash_command(name="clearall", description="Clears all Messages")
@commands.has_permissions(manage_messages = True)
async def clearall(ctx):
    await ctx.channel.purge()
    # 直接设置delete_after参数,5秒后自动删除这条响应
    await ctx.respond("Done!", delete_after=5)

@clearall.error
async def clearerror(ctx, error):
    if isinstance(error, MissingPermissions):
        await ctx.respond("Do you have manage message permissions?")
    else:
        raise error

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.08 04:35:26