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
相关产品推荐
相关产品推荐

