【问题标题】:How can I get my bot to DM a specific user on command?如何让我的机器人根据命令向特定用户发送 DM?
【发布时间】:2020-07-28 06:59:43
【问题描述】:

我想知道我的机器人是否可以在用户发送命令后向我发送直接消息。例如,假设用户发送一个命令,机器人回复用户一条消息说please wait for admin,而机器人还直接向我发送一条消息说a user has requested for help。如果我没有任何方法可以做到这一点,有没有类似的方法可以做到这一点?

【问题讨论】:

    标签: discord.js


    【解决方案1】:

    您可以这样发送 DM:

    user.send("Your message");
    

    所以它看起来像这样:

    const Discord = require("discord.js");
    
    let client = new Discord.Client(),
        prefix = "!";
    
    client.on("message", (message) => {
    
     if (message.content.startsWith(prefix)) {
    
      let args = message.content.slice(prefix.length).split(" "),
          cmd  = args.shift();
    
      if (cmd === "your_command") {
    
       message.author.send("please wait for admin");
       client.users.cache.get("your_user_id").send("a user has requested for help");
    
      }
    
     }
    
    });
    

    【讨论】:

    • 它说 TypeError: client.users.get is not a function
    • 哦,我刚刚编辑了我的答案。这是client.users.cache.get() :)
    • 如果可行,请单击复选标记并将此帖子标记为已解决:)
    猜你喜欢
    • 2021-12-23
    • 2021-06-13
    • 2018-05-10
    • 2021-12-03
    • 2019-12-11
    • 2019-03-09
    • 2022-10-13
    • 2021-02-24
    相关资源
    最近更新 更多