最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Discord.js How to mention message author? - Stack Overflow

programmeradmin6浏览0评论

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

But I want:

@(msg-author-username) pong

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

But I want:

@(msg-author-username) pong

Share Improve this question edited May 18, 2023 at 10:21 stickynotememo 17913 bronze badges asked Feb 8, 2021 at 17:51 TimeToLearnTimeToLearn 631 gold badge1 silver badge5 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

There's actually a really simple function that's already in the discord.js module that provides that to you.

Instead of writing ${user.username} pong, you can do message.reply('pong')... however this formats it into @user, pong. So it adds a ma.

An alternate method is to simply do message.channel.send('<@' + message.author.id + '> pong'); in order to not use the ma. But I prefer message.reply simply because it's a lot less typing to deal with lol.

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. Then, from that, you can simply do 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!

发布评论

评论列表(0)

  1. 暂无评论