amtixdev-timestamp-generator

1.0.0 • Public • Published

amtixdev-timestamp-generator

Discord server NPM version NPM downloads

AmtiXDev

AmtiXDev Timestamp Generator

A simple npm package to generate Discord timestamps based on user-specified durations.

Installation

Install the package using npm:

npm install amtixdev-timestamp-generator

Usage

const generateTimestamp = require('amtixdev-timestamp-generator');

// Example: Generate timestamp for 1 day
const timestamp = generateTimestamp('1d');
console.log(`Generated timestamp: ${timestamp}`);

Replace the duration string in the generateTimestamp function with your desired time value (e.g., '1d' for 1 day, '2h' for 2 hours).

API

generateTimestamp(duration: string): string

Generates a Discord timestamp based on the specified duration.

  • duration: A string representing the duration in the format 'XdXhXmXs' where X is a number and d/h/m/s denote days/hours/minutes/seconds.

Returns a string containing the Discord timestamp.

Discord Bot Integration

You can also use this package in your Discord bot. Here's an example using discord.js:

const { Client, Intents } = require('discord.js');
const generateTimestamp = require('amtixdev-timestamp-generator');

// Replace with your bot token
const token = 'YOUR_BOT_TOKEN';

const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });

client.on('messageCreate', async (message) => {
    if (message.author.bot) return; // Ignore messages from bots

    if (message.content.startsWith('!create_time')) {
        const args = message.content.split(' ').slice(1);

        if (args.length !== 1) {
            message.reply('Please provide a valid time value. Example: `!create_time 1d`');
            return;
        }

        const duration = args[0];
        const timestamp = generateTimestamp(duration);
        message.reply(`Time: ${timestamp}`);
    }
});

client.login(token);

Preview

Preview Image

/amtixdev-timestamp-generator/

    Package Sidebar

    Install

    npm i amtixdev-timestamp-generator

    Weekly Downloads

    6

    Version

    1.0.0

    License

    ISC

    Unpacked Size

    4.98 kB

    Total Files

    3

    Last publish

    Collaborators

    • amtixdev