You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在nextcord/discord.py中给斜杠命令发送者发私信?

问题修复方案

错误原因很明确:interaction.response对象不存在author属性,你找错了获取用户的路径,同时Nextcord中发送消息的方法也用错了。

修复后的代码:

@bot.slash_command()
async def test(interaction: nextcord.Interaction):
    # 先响应交互请求,防止Discord判定命令超时
    await interaction.response.send_message("测试私信已发送!", ephemeral=True)
    # 给触发命令的用户发送私信
    await interaction.user.send("Test DM")

关键说明:

  • 触发命令的用户对象是interaction.user,而非interaction.response.author
  • 发送私信使用send()方法,不是send_message()
  • 必须先调用interaction.response的相关方法完成交互响应,否则会出现命令超时错误,ephemeral=True可让回复仅对触发用户可见

内容的提问来源于stack exchange,提问作者NotM1guel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 10:16:22