Making discord bot mention someone

不打扰是莪最后的温柔 提交于 2021-02-11 12:40:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!