更改 Discord 机器人的时间和日期格式
Changing the time and date format for Discord bot
所以,标题简要说明了我的问题。我正在为我的机器人创建一个踢球功能,它运行良好。我遇到的唯一问题(不是主要问题)是将带有踢球信息的嵌入发送到 #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 来生成这个日期和时间,但是,它的格式是混乱和混乱的。
我希望时间和日期格式设置为 DD/MM/YYYY HH:MM AM/PM 基于澳大利亚东部标准时间 (AEST ).我怎样才能做到这一点?
当您使用嵌入时,您可以使用 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。
所以,标题简要说明了我的问题。我正在为我的机器人创建一个踢球功能,它运行良好。我遇到的唯一问题(不是主要问题)是将带有踢球信息的嵌入发送到 #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 来生成这个日期和时间,但是,它的格式是混乱和混乱的。
我希望时间和日期格式设置为 DD/MM/YYYY HH:MM AM/PM 基于澳大利亚东部标准时间 (AEST ).我怎样才能做到这一点?
当您使用嵌入时,您可以使用 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。