【问题标题】:How to send message to a specific user from discord bot using discor.js如何使用 discord.js 从 discord bot 向特定用户发送消息
【发布时间】:2020-09-10 11:09:33
【问题描述】:

我想使用我的 discord id 将消息从我的 discord 机器人发送给像我这样的特定用户。 我尝试了以下代码,其中我的客户端对象被命名为 bot:

bot.users.get("My Id copied from discord").send("Message to Send");

但它在终端中给出以下错误:

bot.users.get 不是函数

请帮助我解决此错误。 谢谢

【问题讨论】:

    标签: discord discord.js


    【解决方案1】:

    从 discord.js v12 开始,您需要使用 cache 访问 users 集合

    bot.users.cache.get('ID').send('hello')
    

    您需要改用users.fetch(),因为用户可能不会被缓存

    const user = await bot.users.fetch('ID')
    user.send('hello')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-06-26
      • 2018-08-27
      • 1970-01-01
      • 1970-01-01
      • 2020-11-26
      • 2020-08-25
      • 2023-03-27
      相关资源
      最近更新 更多