如何让我的机器人提及发出该机器人命令的人

时间:2021-02-07 18:46:29

标签: javascript node.js discord.js

我正在制作一个不和谐的机器人,我想这样做:有人输入 -ping,机器人回复 @theuserwhotyped-ping

我没有错误,我只是不知道如何编码,而且我在互联网上找不到任何解决方案。

这是我制作的代码:

const Discord = require("discord.js");

const client = new Discord.Client();

const prefix = "-";

client.on("message", message=>{
    if(!message.content.startsWith(prefix) || message.author.bot) return;


const args = message.content.slice(prefix.length).split(" ");
const command = args.shift().toLowerCase();

if (command === "ping"){
    message.channel.send("@{user}); //this is the line which dont work
    }
});

1 个答案:

答案 0 :(得分:2)

您可以使用 message.reply

message.reply('typed ping');

它发送一个回复,比如 @peter, typed ping

或者使用 message.author:

message.channel.send(`${message.author} typed ping`);

它发送类似 @peter typed ping 的消息。