本文介紹了如何讓我的機器人提及發(fā)出該機器人命令的人的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在制作一個不和諧的機器人,我想這樣做:有人輸入 -ping
并且機器人以 @theuserwhotyped-ping
響應.
I am making a discord bot, and I want to do this: someone type -ping
and the bot responds with @theuserwhotyped-ping
.
我沒有錯誤,就是不知道怎么編碼,網(wǎng)上也沒找到解決辦法.
I have no errors, I just don't know how to code it, and I don't find any solution on the Internet.
這是我制作的代碼:
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
}
});
推薦答案
你可以使用 message.reply
:
message.reply('typed ping');
它發(fā)送一個回復,例如 @peter,輸入 ping
.
It sends a reply, like @peter, typed ping
.
或者使用message.author
:
message.channel.send(`${message.author} typed ping`);
它發(fā)送類似 @peter typed ping
的消息.
It sends a message like @peter typed ping
.
這篇關(guān)于如何讓我的機器人提及發(fā)出該機器人命令的人的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!