问题
How do I make my bot mention someone on the server?
module.exports = {
name: 'mention',
description: 'this is a mention command!',
execute(message) {
mention = message.mentions.users.first();
message.channel.send('Hello' + mention);
},
};
I thought it would work but it doesn't. Is there another way to mention someone?
回答1:
message.mentions.users.first()
returns an object, which is why it's not working. This is the correct way to mention someone:
mention = message.mentions.users.first();
message.channel.send(`Hello <@${mention.id}>`);
For future reference, here are the formats for all mentions:
'<@{user.id}>' // user mention
'<#{channel.id}>' // channel mention
'<@&{role.id}>' // role mention
'<(a):{emoji.name}:{emoji.id}>' // emote (use 'a' at the front if emote is animated)
来源:https://stackoverflow.com/questions/63861647/making-discord-bot-mention-someone