简体   繁体   English

我有一个用户信息命令,并使用.createdAt在日期创建。 我不能像以前那样设计风格

[英]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.

相关问题 我有一个javascript函数,我无法分辨自己做错了什么 - I have a javascript function, and I can't tell what I've done wrong 我正在为Discord机器人执行用户信息命令,并想知道是否有一种方法可以使.createdAt看起来更好 - I am making a user info command for my Discord bot, and wondering if there is a way to make .createdAt look nicer 如何编辑我之前使用联系表单创建的联系人? - How can I edit a contact that I have previously created with an contact form? 为什么不能删除在Electron中使用fs-extra创建的目录? - Why can't I delete the directory that I've created using fs-extra in Electron? 我创建了一个扩展,但是加载时找不到依赖项 - I've created an extension, but when loaded can't find a dependency 为什么即使我已经安装了 Gatsby 命令也无法工作? - why can't Gatsby command work even if I have installed it? 我使用 javascript 在 HTML 中创建了一个表格 - I have created a table in HTML using javascript 在我的 userinfo 命令中,我应该怎么做,我不必使用此人的 ID 并 ping 他们。 它将显示使用 cmd 的人的信息 - In my userinfo command how should i do that I don’t have to use the ID of the person and ping them. It will show the info of the person using the cmd 我已经编写了自己的javascript bencode库,但仍然无法生成种子信息哈希? - I've written my own javascript bencode library and I still can't generate torrent info hashes? 使用angularjs时在哪里包含javascript文件。 我所做的似乎不起作用 - Where to include javascript files while using angularjs. What i have done doesn't seem to be working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM