发送带按钮的Discord临时消息报错:send_with_components不支持ephemeral参数
问题原因与解决方法
错误原因
ephemeral 是Discord交互响应专属参数,仅用于交互相关的消息发送方法(如 interaction.response.send_message()),而你使用的 interaction.channel.send() 是向频道发送普通公共消息的方法,本身不支持这个参数,因此抛出错误。
另外,临时消息(仅触发交互的用户可见)只能通过交互响应/后续跟进方法实现,直接调用频道发送方法无法生成临时消息。
解决方案
根据你的需求,替换为交互响应方法即可:
情况1:首次响应交互(未发送过任何响应)
使用 interaction.response.send_message(),保留所有参数:
await interaction.response.send_message( f'<@{interaction.author.id}>', embed=embed, components=[ Button(label='News', custom_id="button-give-news", style=ButtonStyle.grey), Button(label='Media', custom_id="button-give-media", style=ButtonStyle.red) ], ephemeral=True )
情况2:已发送过交互响应(比如之前调用过 interaction.response.defer())
使用 interaction.followup.send() 发送后续临时消息:
await interaction.followup.send( f'<@{interaction.author.id}>', embed=embed, components=[ Button(label='News', custom_id="button-give-news", style=ButtonStyle.grey), Button(label='Media', custom_id="button-give-media", style=ButtonStyle.red) ], ephemeral=True )
补充说明
interaction.channel.send()发送的消息会对频道内所有成员可见,不存在临时消息的设置项;- 只有通过
interaction.response或interaction.followup系列方法发送的消息,才能通过ephemeral=True标记为仅触发交互的用户可见。
内容的提问来源于stack exchange,提问作者Felace
相关产品推荐
相关产品推荐

