Slash delete命令错误,交互未知。

huangapple go评论82阅读模式
英文:

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=&quot;cleanup&quot;, description=&quot;Well... it cleans... what else do you think it does (:)&quot;)
@commands.has_permissions(manage_messages=True)
@app_commands.describe(all=&quot;Delete all messages in this channel&quot;,
                       amount=&quot;Delete a specific amount of messages (1 to 100)&quot;)
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&quot;All messages in this channel have been deleted.&quot;)
        elif amount:
            if amount &lt; 1 or amount &gt; 100:
                await interaction.response.send_message(f&quot;Please enter a number between 1 and 100 for the &#39;amount&#39; option.&quot;)
            else:
                await interaction.channel.purge(limit=amount)
                await interaction.response.send_message(f&quot;{amount} messages have been deleted in this channel.&quot;, ephemeral=True)
        else:
            await interaction.response.send_message(f&quot;Please provide one of the options: &#39;all&#39; or &#39;amount&#39;.&quot;)
    except Exception as e:
        print(f&quot;An error occurred: {e}&quot;)

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.

huangapple
  • 本文由 发表于 2023年7月23日 13:15:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76746723.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定