如何获取发送消息的用户的 ID?
How do I get the ID of a user that sent the message?
我想提及发送命令的用户。我知道我的代码风格很奇怪,但我喜欢 JavaScript 之类的函数。
这就是我尝试过的方法,它提到用户使用发送的参数。
因此,例如,如果您执行 !mention <user_id>
,它会提及该用户。我想从发送的用户那里自动检测到这个。
function pingFunction(arguments, receivedMessage) {
if (arguments > 0) {
receivedMessage.channel.send("<@" + arguments + ">");
} else {
receivedMessage.channel.send("<@" + arguments + ">");
}
}
提前致谢!
获取消息发送者 ID 的方法是 message.author.id
,或者在您的情况下是 receivedMessage.author.id
。
从那里,您可以替换 receivedMessage.channel.send("<@" + arguments + ">")
receivedMessage.channel.send("<@" + message.author.id + ">");
我想提及发送命令的用户。我知道我的代码风格很奇怪,但我喜欢 JavaScript 之类的函数。
这就是我尝试过的方法,它提到用户使用发送的参数。
因此,例如,如果您执行 !mention <user_id>
,它会提及该用户。我想从发送的用户那里自动检测到这个。
function pingFunction(arguments, receivedMessage) {
if (arguments > 0) {
receivedMessage.channel.send("<@" + arguments + ">");
} else {
receivedMessage.channel.send("<@" + arguments + ">");
}
}
提前致谢!
获取消息发送者 ID 的方法是 message.author.id
,或者在您的情况下是 receivedMessage.author.id
。
从那里,您可以替换 receivedMessage.channel.send("<@" + arguments + ">")
receivedMessage.channel.send("<@" + message.author.id + ">");