英文:
Slash delete command error unknown interaction
问题
当我调用amount
选项时,它会删除消息,但Discord机器人会保持思考状态,然后显示app not responding
,只有当我删除单个消息时才能正常工作。如果我使用all
来清理所有消息,也可以正常工作。但如果删除多个消息,它会完成任务,但在Discord中引发错误,并在控制台中显示An error occurred: 404 Not Found (error code: 10062): Unknown interaction
。这是我用于删除的斜杠命令:
@bot.tree.command(name="cleanup", description="Well... it cleans... what else do you think it does (:)")
@commands.has_permissions(manage_messages=True)
@app_commands.describe(all="Delete all messages in this channel",
amount="Delete a specific amount of messages (1 to 100)")
async def cleanup(interaction: discord.Interaction, all: bool = False, amount: int = None):
try:
if all:
await interaction.channel.purge(limit=None)
await interaction.response.send_message("All messages in this channel have been deleted.")
elif amount:
if amount < 1 or amount > 100:
await interaction.response.send_message("Please enter a number between 1 and 100 for the 'amount' option.")
else:
await interaction.channel.purge(limit=amount)
await interaction.response.send_message(f"{amount} messages have been deleted in this channel.", ephemeral=True)
else:
await interaction.response.send_message("Please provide one of the options: 'all' or 'amount'.")
except Exception as e:
print(f"An error occurred: {e}")
我尝试过使用Chat GPT,但它一直抛出旧的discord_slash_commands已弃用版本的命令。
英文:
I need some help here I have this delete command with 2 options (amount and all)
when i call ammount it deletes the message but discord bot stays thinking and then says app not responding
, it only works fine if i delete just 1 message. and if i use to clean all.
but if its more than 1 it does the job but throws the error in discord and in console it says An error occurred: 404 Not Found (error code: 10062): Unknown interaction
this is my slash command for deletion
@bot.tree.command(name="cleanup", description="Well... it cleans... what else do you think it does (:)")
@commands.has_permissions(manage_messages=True)
@app_commands.describe(all="Delete all messages in this channel",
amount="Delete a specific amount of messages (1 to 100)")
async def cleanup(interaction: discord.Interaction, all: bool = False, amount: int = None):
try:
if all:
await interaction.channel.purge(limit=None)
await interaction.response.send_message(f"All messages in this channel have been deleted.")
elif amount:
if amount < 1 or amount > 100:
await interaction.response.send_message(f"Please enter a number between 1 and 100 for the 'amount' option.")
else:
await interaction.channel.purge(limit=amount)
await interaction.response.send_message(f"{amount} messages have been deleted in this channel.", ephemeral=True)
else:
await interaction.response.send_message(f"Please provide one of the options: 'all' or 'amount'.")
except Exception as e:
print(f"An error occurred: {e}")
I tried chat gpt but it keeps throwing old discord_slash_commands deprecated version commands haha
答案1
得分: 1
你必须在3秒内回复,不论如何。你在回复之前要清理一下,所以可能会超过截止时间。
如果在应用程序命令中需要执行一些较慢的操作,可以使用 defer()
和 followup
来稍后回复。
附注:all
是Python中的内置关键字,正如语法高亮(和你的Linter)所建议的那样。不要遮蔽内置关键字。
英文:
You have to respond within 3 seconds, no matter what. You're purging before responding, so you probably exceed the deadline.
If you have to do something slow in an app command, you can use defer()
, and followup
to respond later on.
P.s. all
is a built-in keyword in Python, as the syntax highlighting (and your Linter) suggest. Don't shadow built-ins.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论