【问题标题】:I have a user info command, and have the created at date using .createdAt. I can't stylize this as I've done previously我有一个用户信息命令,并使用 .createdAt 创建了日期。我不能像以前那样对它进行风格化
【发布时间】:2019-04-11 09:03:06
【问题描述】:

我的机器人上有一个用户信息命令,并使用了一个风格化的 .createdAt,根据此处另一个用户的帮助。这适用于 message.author,但不适用于我定义为 memberInfo 的内容,它在提及用户时使用。 let memberInfo = message.mentions.members.first(); 定义了它,我用const date = message.author.createdAt; const newDate = date.toLocaleDateString(); 对其进行了风格化。我怎样才能做到这一点,所以 memberInfo createdAt 不仅仅是时区和时间等的正常字符串。

【问题讨论】:

    标签: javascript node.js bots discord discord.js


    【解决方案1】:

    这取决于你想要什么

       new Date(newDate).valueOf() //1554418800000
    

    【讨论】:

      【解决方案2】:

      首先,我建议使用dateformat 轻松进行更多自定义。

      要回答您的问题,请使用message.mentions.users.first()。如果您已经有一个成员对象,您可以简单地使用user 属性,即member.user。你的代码应该是这样的......

      const user = message.mentions.users.first() || message.author;
      
      const date = user.createdAt.toLocaleDateString();
      

      请记住,正确解析参数而不是使用message.mentions 是一种很好的做法。如果允许提及机器人作为前缀,则您当前的代码将返回机器人而不是预期用户。

      【讨论】:

        猜你喜欢
        • 2023-04-01
        • 2021-11-30
        • 2012-07-13
        • 2019-08-25
        • 1970-01-01
        • 2018-07-17
        • 1970-01-01
        • 1970-01-01
        • 2013-02-20
        相关资源
        最近更新 更多