javascript - How do I get the ID of a user that sent the message? - Stack Overflow

I want to mention the user that sent the mand. I know my code style is weird, but I like the JavaScript

I want to mention the user that sent the mand. I know my code style is weird, but I like the JavaScript like functions.

So this is what I've tried, it mentions the user using the arguments sent. So for example, if you did !mention <user_id> it would mention the user. I want to auto-detect this from the user sent.

function pingFunction(arguments, receivedMessage) {
  if (arguments > 0) {
    receivedMessage.channel.send("<@" + arguments + ">");
  } else {
    receivedMessage.channel.send("<@" + arguments + ">");
  }
}

Thanks in advance!

I want to mention the user that sent the mand. I know my code style is weird, but I like the JavaScript like functions.

So this is what I've tried, it mentions the user using the arguments sent. So for example, if you did !mention <user_id> it would mention the user. I want to auto-detect this from the user sent.

function pingFunction(arguments, receivedMessage) {
  if (arguments > 0) {
    receivedMessage.channel.send("<@" + arguments + ">");
  } else {
    receivedMessage.channel.send("<@" + arguments + ">");
  }
}

Thanks in advance!

Share Improve this question edited Dec 26, 2018 at 12:22 Federico Grandi 6,7865 gold badges33 silver badges51 bronze badges asked Dec 26, 2018 at 2:29 user10738016user10738016
Add a ment  | 

1 Answer 1

Reset to default 1

The way to get id of the person who sent the message is message.author.id, or in your case, receivedMessage.author.id.

From there, you can replace receivedMessage.channel.send("<@" + arguments + ">") receivedMessage.channel.send("<@" + message.author.id + ">");

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744321403a4568432.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信