claire.png
claire.png

Reputation: 232

change .joinedAt format in discord.js

I'm making a user info command, and i want it to say when a user joined, it kinda works but i want to change the time format, this is the code that gets the join data:

message.member.joinedAt

i tried using .format('YYYY-MM-DD') right after joinedAt but nothing, this is what it looks like right now (it has italian text for some reason, probably because my discord account is registered in Italy)enter image description here

Upvotes: 0

Views: 634

Answers (1)

Tyler2P
Tyler2P

Reputation: 2370

You can use a package called moment.
Example:

const moment = require('moment');
moment.utc(<Message>.member.joinedAt).format('YYYY-MM-DD');

Full example:

const Discord = require('discord.js'); // Define Discord
const client = new Discord.Client(); // Define client
const moment = require('moment'); // Define moment
let prefix = 'your-prefix'; // Define your bots prefix

client.on('message', function(message) { // Message event listener
    if (message.content.startsWith(`${prefix}info`)) { // If the message starts with the command
        message.channel.send(`<@!${message.author.id}>, you joined this server on ${moment.utc(message.member.joinedAt).format('YYYY-MM-DD')}`);
    }
});

Upvotes: 1

Related Questions