【问题标题】:How to make bot send Direct Message To Someone that the bot don't have it in mutal servers and have his id如何让机器人发送直接消息给该机器人在互服务器中没有它并且有他的 ID 的人
【发布时间】:2019-10-17 02:02:45
【问题描述】:

我想知道我可以让用户知道机器人不在他的共同服务器中并且我有他的 ID 我希望机器人向他发送直接消息的代码是什么?

我没有尝试任何我在学习方面的菜鸟

【问题讨论】:

  • 这是不可能的。虽然您可以检索用户,但除非机器人与他们共享服务器,否则您将无法向他们发送消息

标签: node.js discord discord.js


【解决方案1】:

使用Client.fetchUser() 方法。

示例 1:

let ID = '123456789012345678';

client.fetchUser(ID)
  .then(user => user.send('hello'))
  .catch(console.error);

示例 2 (必须在异步函数中)

let ID = '123456789012345678';

try {
  let user = await client.fetchUser(ID);
  await user.send('hello');
} catch(err) {
  console.error(err);
}

【讨论】:

  • 如果一个机器人不与该用户共享一个共同的公会,它就不能 DM 用户
猜你喜欢
  • 2021-03-19
  • 2020-12-03
  • 2022-01-19
  • 2019-06-20
  • 2020-12-31
  • 2023-02-06
  • 2019-07-27
  • 2018-05-26
  • 2022-01-03
相关资源
最近更新 更多