@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
清除系统我认为是交互错误消息被删除,但出现错误
1条答案
按热度按时间unguejic1#
当您对交互响应太慢时会发生这种情况。您必须始终在3秒内响应,否则您的交互将失败。
如果您需要超过3秒钟,可以使用
defer()
,然后使用followup
回复。考虑到您要在答复前清除邮件这一事实,您将不再及时。您应该首先推迟,然后执行您想要的操作,再发送后续邮件。
注意你只能回复一次。你必须对连续的消息使用followup(或
channel.send
),否则它也会出错。还有:
is
代替==
进行None
检查