Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在discord.js中使用message.channel.send正确标记用户_Javascript_Node.js_Discord.js - Fatal编程技术网

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

Javascript 如何在discord.js中使用message.channel.send正确标记用户,javascript,node.js,discord.js,Javascript,Node.js,Discord.js,如何在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 mau

如何在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)[带有消息.delete();disabled]


执行时没有控制台日志。

从bot中提到的内容有点不同。您需要使用

但是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