amtixdev-timestamp-generator
v1.0.0
Published
A simple npm package to generate Discord timestamps based on user-specified durations.
Downloads
7
Maintainers
Readme
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);