【问题标题】:how to make my bot mention the person who gave that bot command如何让我的机器人提及发出该机器人命令的人
【发布时间】:2021-05-11 11:27:45
【问题描述】:

我正在制作一个不和谐的机器人,我想做这个:有人输入-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
    }
});

【问题讨论】:

    标签: javascript node.js discord.js


    【解决方案1】:

    您可以使用message.reply:

    message.reply('typed ping');
    

    它会发送回复,例如@peter, typed ping

    或使用message.author

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

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

    【讨论】:

    • 我不建议使用Message#reply,因为下一个主要版本的 DJS (v13) 将替换该方法以用作内联回复。
    • 感谢@Elitezen 提供的信息
    猜你喜欢
    • 2019-06-29
    • 2021-04-14
    • 2018-08-27
    • 2021-01-27
    • 2020-11-04
    • 2019-04-16
    • 1970-01-01
    • 1970-01-01
    • 2021-10-05
    相关资源
    最近更新 更多