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:
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@(msg-author-username) pong
1 Answer
Reset to default 6There'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!