最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin5PV0评论

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 + ">");

Post a comment

comment list (0)

  1. No comments so far