python discord.py 代码:404您访问的页面不存在(错误代码:10062):未知相互作用

k7fdbhmy  于 2023-01-01  发布在  Python
关注(0)|答案(1)|浏览(112)
@bot.tree.command(name="clear", description="admin only", guild=discord.Object(guildid))
async def clear(interaction: discord.Interaction, amount : int = None):
     if not interaction.user.guild_permissions.manage_messages:
         return
     if amount == None:
         embed = discord.Embed(title="**📛 Error**", description=f"Please enter the amount to be deleted",color=0xff0000, timestamp = datetime.datetime.now())
         await interaction.response.send_message(embed=embed)
     else:
         await interaction.channel.purge(limit=amount)
         embed = discord.Embed(title="**🧹 Chat Cleaning **", description=f"{amount} recent chats have been deleted", color = 0xFFFD05, timestamp = datetime.datetime.now())
         await interaction.response.send_message(embed=embed)
         await asyncio. sleep(2)
         await interaction.channel.purge(limit=1)
File "C:\Users\Heeryun\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\app_commands\tree.py", line 1242, in _call
    await command._invoke_with_namespace(interaction, namespace)
  File "C:\Users\Heeryun\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\app_commands\commands.py", line 887, in _invoke_with_namespace
    return await self._do_call(interaction, transformed_values)
  File "C:\Users\Heeryun\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\app_commands\commands.py", line 880, in _do_call
    raise CommandInvokeError(self, e) from e
discord.app_commands.errors.CommandInvokeError: Command 'clear' raised an exception: NotFound: 404 Not Found (error code: 10062): Unknown interaction

清除系统我认为是交互错误消息被删除,但出现错误

unguejic

unguejic1#

当您对交互响应太慢时会发生这种情况。您必须始终在3秒内响应,否则您的交互将失败。
如果您需要超过3秒钟,可以使用defer(),然后使用followup回复。
考虑到您要在答复前清除邮件这一事实,您将不再及时。您应该首先推迟,然后执行您想要的操作,再发送后续邮件。
注意你只能回复一次。你必须对连续的消息使用followup(或channel.send),否则它也会出错。
还有:

  • 代替在2秒后手动删除消息,你可以使它暂时(因此只有用户可以看到它,并且他们可以手动消除它)。
  • 第一个if语句永远不会发送响应,所以它总是会在Discord中导致错误。最好是向用户发送实际的错误消息,而不是让命令失败。您可以再次使其短暂。
  • 使用is代替==进行None检查

相关问题