【问题标题】:Saving variable of a message in discord.js在 discord.js 中保存消息的变量
【发布时间】:2022-01-17 02:56:48
【问题描述】:

我喜欢将我发送的 DM 保存到本地变量中的用户。我怎样才能做到这一点? 我想对该消息做出反应,但如果我在所需的 .catch() 块之后或之前使用 .then(),日志会显示“无法向该用户发送消息”,没有它,我可以发送消息。 .

谢谢!!

代码:

client.users.cache
  .get(memb.id)
  .send(emb5)
  .catch((msb) => {
    write("Error");
  })
  .then((msg) => {
    msg.react(one);
  });

一个是表情符号...

【问题讨论】:

  • 您确定该会员没有屏蔽他们的私信吗?
  • 否则只是获取之前的用户,他肯定不在缓存中。
  • @Leau (1) 我自己测试过,没有屏蔽dm的...

标签: javascript discord discord.js try-catch


【解决方案1】:

如果您在 async function 中,您可以将消息放入如下变量中:

const user = await client.users.fetch(mem.id); // Fetching the user
const awaitedMessage = await user.send(emb5); // Send the message to the user
awaitedMessage.react(one); // React the sent message

【讨论】:

  • 这很好用!谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-08-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-25
  • 2022-01-07
相关资源
最近更新 更多