Discord 机器人在发送嵌入后返回错误

问题描述 投票:0回答:1

好吧,我在 python 中制作了一个简单的不和谐机器人,在收到命令 /student 后,它应该发送一条嵌入消息。但发送后仍然显示发送命令,大约 5 秒后它返回错误“应用程序没有响应”。该命令的代码如下所示:

@bot.tree.command(name="student", description="Přidá studenta do databáze")
async def student(interaction:discord.Interaction):
    embed = discord.Embed(title="REGISTRACE ŽÁKA", description="Zaregistrování žáka do databáze", color=0x009ade)
    embed.add_field(name="Jméno", value="napiš jméno žáka", inline=False)
    embed.set_footer(text="Střední ScioŠkola Brno")
    await interaction.channel.send(embed=embed)

我期望该命令发送嵌入消息,但什么也没有。但它试图做某事却什么也做不了。

python discord.py
1个回答
0
投票

这是因为您实际上并未回复该消息。

interaction.channel.send
所做的只是发送请求,让机器人在频道中发送消息。

要响应应用程序命令,请使用 InteractionResponse,您可以从

Interaction
中的 response 属性中使用它。

@bot.tree.command()
async def mycommand(interaction: discord.Interaction):
    await interaction.response.send_message(content="This is a command response")

请注意,一个命令只能响应一次,并且必须在命令调用后 3 秒内响应。

© www.soinside.com 2019 - 2024. All rights reserved.