当用户加入一些用户信息时,我正在尝试使漫游器显示嵌入的内容。
我能够获得用户名,头像和公会成员总数。
问题是当我使用.addField('Date Joined', member.user.createdAt, true)
时确实显示了日期,但其格式如下:
Date Joined Mon Nov 26 2018 19:11:11 GMT-0500 (Eastern Standard Time)
我怎么只显示日期和简化的时间,例如
mm: dd: yyyy HH: MM
const Discord = require('discord.js');
const client = new Discord.Client();
const auth = require('./auth.json');
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
// Create an event listener for new guild members
client.on('guildMemberAdd', member => {
// Send the message to a designated channel on a server:
const channel = member.guild.channels.find(ch => ch.name === 'join-leaves');
// Do nothing if the channel wasn't found on this server
if (!channel) return;
// Send the message, mentioning the member
let embed = new Discord.RichEmbed()
.setTitle("Welcome")
.setAuthor(`${member.user.tag} Has Joined.`, member.user.displayAvatarURL,)
.setThumbnail(member.user.displayAvatarURL)
.addField('Date Joined', member.user.createdAt, true)
.addField('Total Members', member.guild.memberCount, true)
channel.send(embed);
});
client.login(auth.token);
答案 0 :(得分:0)
您可以尝试使用npm package dateformat
并将其添加到您的代码中:
var dateFormat = require('dateformat');
.addField('Date Joined', dateFormat(member.user.createdAt, "mm:dd:yyyy h:MM"), true)
或者尝试使用toLocaleDateString