This shows user information, including discord account creation date. Credits to Jacoblee for assisting with the formula and Lucky Guy for helping with date formatting.
/// Setup:
// 1. Go to (https://autocode.com/tools/discord/command-builder/).
// 2. Create a slash command named userinfo.
// 3. Open the options drop-down menu.
// 4. Change the first field as STRING.
// 5. Change the second field as USER_ID.
// 6. Change the third field as USER_ID.
// 7. Click save all.
// 8. Go back to the file and set the endpoint as DISCORD and COMMAND.
// 9. In the field below the top ones, set that as the name of the command, USERINFO.Setup:
/// start of code
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
// turning the date into actual data
const moment = require('moment');
function convertIDtoUnix(id) {
/* Note: id has to be str */
let bin = (+id).toString(2);
let unixbin = '';
let unix = '';
let m = 64 - bin.length;
unixbin = bin.substring(0, 42 - m);
unix = parseInt(unixbin, 2) + 1420070400000;
return unix;
}
function convert(id) {
let unix = convertIDtoUnix(id.toString());
let timestamp = moment.unix(unix / 1000);
return timestamp;
}
// waiting for response
let userID = context.params.event.data.options[0].value;
// defining and fetching information about user
let userInfo = await lib.discord.guilds['@0.1.0'].members.retrieve({
user_id: `${userID}`,
guild_id: context.params.event.guild_id,
});
// defining separate things to get information for the embed
let username = userInfo.user.username;
let useravatar = userInfo.user.avatar_url;
let userid = userInfo.user.id;
let userdisc = userInfo.user.discriminator;
let joindate = moment(convert(userid)).format('DD-MMM-YYYY');
let serverjoindate = moment(userInfo.joined_at).format('DD-MMM-YYYY');
// output
await lib.discord.channels['@0.3.2'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `Gathered Information on ${username} ~`,
embed: {
title: `${username}#${userdisc}`,
type: 'rich',
color: 0x0000ff, // blue
fields: [
{
name: 'Discord ID:',
value: `${userid}`,
},
{
name: `Discord Username:`,
value: `${username}#${userdisc}`,
},
{
name: `Discord Avatar Link:`,
value: `[Click Here](${useravatar})`,
},
{
name: `Discord Join Date:`,
value: `${joindate}`,
},
{
name: `Discord Server Join Date:`,
value: `${serverjoindate}`,
},
],
thumbnail: {
url: `${useravatar}`,
height: 0,
width: 0,
},
},
});