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

如何在discord.js 12.5.3版本中发送仅指定用户可见的公共频道消息?

Discord.js v12.5.3 实现仅指定用户可见消息的方法

你提到的带「Only you can see this」标识的是Discord的临时消息(Ephemeral Message),这类消息不能通过普通的message.channel.send方法主动发送,仅能在响应用户的交互动作(比如斜杠命令、按钮点击、选择菜单操作)时返回。

实现前提

你需要先在Discord开发者后台开启对应应用的交互权限,同时确保你的Bot已经注册了对应的交互命令/组件。

具体实现代码

1. 响应斜杠命令时发送临时消息

client.on('interactionCreate', async interaction => {
  if (!interaction.isCommand()) return;
  if (interaction.commandName === '你注册的命令名称') {
    // 新增ephemeral: true参数即可实现仅触发命令的用户可见
    await interaction.reply({
      content: '这条消息只有你能看到',
      ephemeral: true
    });
  }
});

2. 响应按钮/选择菜单交互时发送临时消息

client.on('interactionCreate', async interaction => {
  if (!interaction.isButton() && !interaction.isSelectMenu()) return;
  if (interaction.customId === '你设置的组件ID') {
    await interaction.reply({
      content: '这条私有消息仅你可见',
      ephemeral: true
    });
  }
});

注意事项

  • 临时消息不会被持久化存储,用户刷新Discord客户端后消息就会消失
  • 只有触发交互的用户能看到这条消息,频道内其他所有用户、甚至Bot本身都无法查看或获取这条临时消息的内容
  • 如果你需要在非交互场景下给指定用户发私有消息,只能走私信通道,调用user.send()方法实现,无法在公共频道直接发送仅单个用户可见的非交互类消息

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.01 21:48:01