【问题标题】:Changing the time and date format for Discord bot [duplicate]更改 Discord bot 的时间和日期格式 [重复]
【发布时间】:2018-12-21 07:56:31
【问题描述】:

所以,标题简要解释了我的问题。我正在为我的机器人创建一个踢球功能,它运行得非常好。我遇到的唯一问题(不是主要问题)是它向 #incidents 频道发送包含踢球信息的嵌入部分,该频道只有机器人和员工可以访问。我已经创建了一个新的 Discord 用户帐户并将其加入服务器。我测试了我的删除命令,它可以正常工作并按照我的意图进行。

var incidentembed = new discord.RichEmbed()
    .setTitle("User removed")
    .setDescription("**" + ruser + "** was successfully removed from the server.") /** ruser declares the user that was removed. **/
    .setColor("#3937a5")
    .addField("Time assigned", message.createdAt, true)
    .addField("Assigned by", `<@${message.author.id}>`, true)
    .addField("Reason", rreason, false); /** rreason declares the reason that the staff member inputted. **/
bot.channels.get("466904829550264322").send(incidentembed); /** The ID points out the #incidents channel. **/

(是的,ClassyAss 是我的 Discord 用户名。)

从屏幕截图可以看出,时间分配字段明显有问题。我正在使用 message.createdAt 来生成这个日期和时间,但是,它的格式是混乱和混乱的。

我希望根据澳大利亚东部标准时间 (AEST) 将时间和日期格式设置为 DD/MM/YYYY HH:MM AM/PM。我怎么能做到这一点?

【问题讨论】:

    标签: javascript discord discord.js


    【解决方案1】:

    当您使用嵌入时,您可以使用 Discord 来显示时间和日期(它也会转换为用户的时间戳)。
    embed.setTimestamp()

    var incidentembed = new discord.RichEmbed()
        .setTitle("User removed")
        .setDescription("**" + ruser + "** was successfully removed from the server.") /** ruser declares the user that was removed. **/
        .setColor("#3937a5")
        .setTimestamp(message.createdAt)
        .addField("Assigned by", `<@${message.author.id}>`, true)
        .addField("Reason", rreason, false); /** rreason declares the reason that the staff member inputted. **/
    bot.channels.get("466904829550264322").send(incidentembed); /** The ID points out the #incidents channel. **/
    

    或者,如果您仍想格式化日期,您可以执行 this 之类的操作。

    var d = new Date,
    dformat = [d.getMonth()+1,
           d.getDate(),
           d.getFullYear()].join('/')+' '+
          [d.getHours(),
           d.getMinutes(),
           d.getSeconds()].join(':');
    

    归功于KooiInc

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多