【问题标题】:dm all command discord jsdm 所有命令不和谐 js
【发布时间】:2022-01-07 15:47:32
【问题描述】:

我希望命令 dm 1 成员,然后等待 5 秒,然后 dm 下一个成员,直到所有成员都被机器人 dm

这是我的代码

if (command === 'dmall') {
  message.guild.members.cache.forEach(async (member) => {
    const messageSent = await member.send(args[0]);
    console.log(messageSent);
    await wait(5000);
  });
}

我得到的错误是 member.send is not function

这是等待它没有问题的东西

let wait = (ms) => {
  if (!ms) throw new TypeError("Time isn't specified");
  return new Promise((resolve) => setTimeout(resolve, ms));
};

【问题讨论】:

  • 您是否向客户添加了GUILD_MEMBERS 意图?

标签: javascript node.js discord discord.js


【解决方案1】:

您的代码对我有用。所以问题可能不在您提供的代码中。

您必须将GUILD_MEMBERSintent 添加到您的客户端才能读取所有公会成员用户数据。

在创建一个新的client 实例时,你应该用这个替换你的代码:

const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS] });

(或者如果您有其他意图,只需添加 Intents.FLAGS.GUILD_MEMBERS 即可。)

注意:此意图是特权。这意味着如果您将此意图添加到您的机器人,it will not be able to join any guild anymore after 100 guild reached until your bot verified。如果这是一个私人机器人。然后就好了。

当您向所有成员发送消息时,请确保在代码中发现错误,以防止您的机器人在以下情况下崩溃:

  • 用户禁用“允许来自服务器成员的直接消息”
  • 用户是机器人。无法向机器人发送 DM。

应该是这样的:

if (command === 'dmall') {
  message.guild.members.cache.forEach(async (member) => {
    const messageSent = await member.send(args[0])
    .catch(err => {console.log(err)});
    console.log(messageSent);
    await wait(5000);
  });
}

告诉我它是否有效。

【讨论】:

    猜你喜欢
    • 2020-08-26
    • 2018-07-21
    • 2022-01-23
    • 1970-01-01
    • 2021-06-30
    • 2021-01-12
    • 2021-07-17
    • 2018-06-08
    • 2021-08-05
    相关资源
    最近更新 更多