【问题标题】:I can't send a message to a specific user in discord.js我无法在 discord.js 中向特定用户发送消息
【发布时间】:2022-01-26 13:42:35
【问题描述】:

我正在尝试创建一个在调用命令时向用户发送消息的系统。但是每当我尝试时,它都会显示TypeError: Cannot read property 'send' of undefined.

这是我正在使用的代码。

 client.users.cache.get("220683253789163520").send("Test")

我使用的是不和谐版本 12。

【问题讨论】:

    标签: javascript node.js discord.js


    【解决方案1】:

    使用Client.users.fetch()直接从API获取

    const user = await client.users.fetch("220683253789163520")
    await user.send("Test")
    

    【讨论】:

      【解决方案2】:

      表示用户没有被缓存,在你需要使用<Client>.users.fetch方法获取用户之前。

      您的案例示例:

      await client.users.fetch('220683253789163520');
      client.users.cache.get('220683253789163520').send('Test');
      

      【讨论】:

      • 我现在收到错误DiscordAPIError: 404: Not Found
      • 现在应该可以了。
      • 谢谢!成功了!
      猜你喜欢
      • 2020-10-01
      • 2021-08-21
      • 2020-04-04
      • 2021-06-10
      • 2020-05-22
      • 2017-12-28
      • 1970-01-01
      • 2019-07-24
      相关资源
      最近更新 更多