【问题标题】:Send message to a specified user向指定用户发送消息
【发布时间】:2019-04-14 04:55:20
【问题描述】:

我正在创建一个机器人,我希望它向指定用户发送私人消息。

例如:

!message @user Welcome to the server!

这将发送“欢迎来到服务器!”给@user。

【问题讨论】:

  • 你试过什么?什么错误?
  • 我试过client.author.get(user).send("Welcome to the server!")。错误信息是Cannot read property 'get' of undefined'
  • 您是否为消息事件创建了监听器?添加与您的原始帖子相关的所有代码。
  • 客户没有作者,所以我认为这是一条消息。消息作者已经是用户,因此您不需要获取作者。并且用户(例如“作者”)有一个 dmChannel 成员,您可以使用该成员向其发送消息。我假设你想做类似message.author.dmChannel.send('Welcome to the server!');

标签: node.js discord discord.js


【解决方案1】:

Discord.js 有一个名为 message#mentions 的属性,你可以这样做

var user = message.mentions.users.first();

如果没有提到用户,这将返回 undefined,或者返回 UserResovleable,然后你可以

user.send("Welcome to the server!");
// or for example
console.log(user.id);

【讨论】:

    猜你喜欢
    • 2019-06-02
    • 2017-10-12
    • 2019-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-08
    • 1970-01-01
    相关资源
    最近更新 更多