简体   繁体   English

Discord.js 如何提及留言作者?

[英]Discord.js How to mention message author?

I searched a lot for the answer, but I didn't find and/or understand it.我搜索了很多答案,但我没有找到和/或理解它。 How can I mention the message author in this code?我如何在此代码中提及消息作者?

It just says:它只是说:

${user.username} pong ${user.username} 乒乓球

But I want:但是我想要:

@(msg-author-username) pong @(msg-author-username) 乒乓球

Btw.顺便提一句。 I'm very new to programming stuff!我对编程很陌生!

There's actually a really simple function that's already in the discord.js module that provides that to you.实际上, discord.js模块中已经有一个非常简单的 function 可以提供给您。

Instead of writing ${user.username} pong , you can do message.reply('pong') ... however this formats it into @user, pong .您可以执行message.reply('pong') ... 而不是编写${user.username} pong ......但是这会将其格式化为@user, pong So it adds a comma.所以它加了一个逗号。

An alternate method is to simply do message.channel.send('<@' + message.author.id + '> pong');另一种方法是简单地执行message.channel.send('<@' + message.author.id + '> pong'); in order to not use the comma.为了不使用逗号。 But I prefer message.reply simply because it's a lot less typing to deal with lol.但我更喜欢message.reply只是因为它可以减少很多输入来处理大声笑。

To align the alt method closer to your code, you could consider setting user to message.author rather than message.author.name since that's just the nickname object instead.要使 alt 方法更接近您的代码,您可以考虑将user设置为message.author而不是message.author.name ,因为那只是昵称 object。 Then, from that, you can simply do message.channel.send(`<@${user.id}> pong`);然后,您可以简单地执行message.channel.send(`<@${user.id}> pong`);

So it should look like:所以它应该看起来像:

const user = message.author;
return message.channel.send(`<@${user.id}> pong`);

Another method:另一种方法:

const user = message.author;
return message.channel.send(`${user} pong`);

Hope this helps!希望这可以帮助!

I searched a lot for the answer, but I didn't find and/or understand it.我搜索了很多答案,但我没有找到和/或理解它。 How can I mention the message author in this code?如何在此代码中提及消息作者?

It just says:它只是说:

${user.username} pong ${user.username} 乒乓球

But I want:但我想要:

@(msg-author-username) pong @(msg-author-username) 乒乓

Btw.顺便提一句。 I'm very new to programming stuff!我对编程很陌生!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM