[英]I have a user info command, and have the created at date using .createdAt. I can't stylize this as I've done previously
I have a user info command on my bot, and use a stylized .createdAt, as per help by another user on here. 我在我的机器人上有一个用户信息命令,并使用一个程式化的.createdAt,根据另一个用户的帮助在这里。 This works for the message.author, but not for what I've defined as memberInfo, which is used when a user is mentioned.
这适用于message.author,但不适用于我定义为memberInfo的内容,该内容在提及用户时使用。
let memberInfo = message.mentions.members.first();
defines it, and I stylize it with const date = message.author.createdAt; const newDate = date.toLocaleDateString();
定义它,并使用
const date = message.author.createdAt; const newDate = date.toLocaleDateString();
对其进行样式化const date = message.author.createdAt; const newDate = date.toLocaleDateString();
const date = message.author.createdAt; const newDate = date.toLocaleDateString();
. 。 How could I make it so the memberInfo createdAt is not just the normal string of timezone and time etc.
我怎么能这样做,所以memberInfo createdAt不仅仅是正常的时区和时间字符串等。
这取决于你想要什么
new Date(newDate).valueOf() //1554418800000
First of all, I'd recommend using dateformat
for a lot more customization easily. 首先,我建议使用
dateformat
轻松实现更多自定义。
To answer your question, use message.mentions.users.first()
. 要回答您的问题,请使用
message.mentions.users.first()
。 If you already have a member object, you could simply use the user
property, ie member.user
. 如果您已有成员对象,则可以只使用
user
属性,即member.user
。 Your code should look something like this... 你的代码应该看起来像这样......
const user = message.mentions.users.first() || message.author;
const date = user.createdAt.toLocaleDateString();
Keep in mind it's good practice to properly parse arguments instead of using message.mentions
. 请记住,正确解析参数而不是使用
message.mentions
是一种好习惯。 If mentioning the bot is allowed as a prefix, your current code would return the bot instead of the intended user. 如果允许将bot作为前缀,那么您当前的代码将返回bot而不是目标用户。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.