0
votes

I'm trying to make the bot display an embed, when a user joins with some user information.

I was able to get the username, avatar and the total guild members.

Problem is when I use .addField('Date Joined', member.user.createdAt, true) it indeed shows the date, but it is formatted like this:

Date Joined Mon Nov 26 2018 19:11:11 GMT-0500 (Eastern Standard Time)

How could I only show the date and simplified time e.g. 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);
1

1 Answers

0
votes

You could try with the npm package dateformat and add this to your code :

var dateFormat = require('dateformat');
.addField('Date Joined', dateFormat(member.user.createdAt, "mm:dd:yyyy h:MM"), true)

Or try with toLocaleDateString