在${user.username}discord.js之前添加文本



我正在尝试构建一个discord bot,我想知道我的代码中有

if (command === 'roast') {
var roasts = ["option 1", "option 2", "option 3", "option 4"];
var randomroast = Math.floor(Math.random() * roasts.length);
if (args[0]) {
const user = getUserFromMention(args[0]);
if (!user) {
return message.reply('Please use a proper mention.');
}

message.channel.send(`${user.username}`);
message.channel.send(roasts[randomroast])
}
}

我想知道我是否可以编辑文本,这样它就会在用户名前面放一个@,在用户名后面放一个吐槽,而不是使用2行

你有一百万种方法可以做到这一点

// The normal way to go...
message.channel.send(`Message Before name ${user.username} Message After name`);
//Others Examples...
let msgBefore = "Before";
let msgAfter = "After";
const nickName = user.username;
message.channel.send(msgBefore + nickName + msgAfter);
//or
message.channel.send("Text-Before " + nickName + " Text-After");
//or
message.channel.send("BEFORE" + `${user.username}` + "AFTER");
//or
message.channel.send(`${msgBefore} ${user.username} ${msgAfter}`);
//Really easy, no?

阅读文档,看看这个Concat的例子(你不需要Concat,但需要学习(:

JavaScript-Concat

就是这样完成的

message.channel.send(`<@${user.id}> , ${roasts[randomroast]}`);

最新更新