【问题标题】:How to properly tag a user using message.channel.send in discord.js如何在 discord.js 中使用 message.channel.send 正确标记用户
【发布时间】:2018-11-30 04:37:46
【问题描述】:

如何在 discord.js 中使用 message.channel.send 正确标记用户?

这是我的代码:

function replaceAll(str, find, replacer) {
      return str.replace(new RegExp(find, 'g'), replacer);
    }
    Bot.on('message', (message) => {
      var mcontent = message.content;
      var mauth = message.author;
      var mtag = mauth.tag;
      if (mcontent.includes("@p")) {
        var newmsg = replaceAll(mcontent, "@p", "@" + mtag);
        message.delete();
        message.channel.send(newmsg);
    });

而且,它会打印:(顺便说一下,我是 hieyou1#6009)[with the message.delete();禁用]

执行时没有控制台日志。

【问题讨论】:

    标签: javascript node.js discord.js


    【解决方案1】:

    来自机器人的提及有点不同。您需要使用<@userid>
    但是 Discord.JS 有一种更简洁的方式来提及用户,而不是使用 message.author.tag,只需使用 message.author。这将标记发送消息的用户。

    message.channel.send(`Hey ${message.author} how's it going?`);
    

    或者用旧的方式连接字符串:

    message.channel.send("Hey " + message.author + " how's it going?");
    

    【讨论】:

    • 我如何从用户标签中获取用户ID?
    • 不知道为什么在这里需要用户 ID,但是:message.author.id@Mikey
    猜你喜欢
    • 2018-05-17
    • 2018-05-15
    • 2021-05-01
    • 1970-01-01
    • 2021-11-01
    • 2021-08-09
    • 2021-09-17
    • 2022-01-10
    • 2020-12-19
    相关资源
    最近更新 更多