chomens-bot-js/commands/time.js

38 lines
1.4 KiB
JavaScript
Raw Normal View History

const { EmbedBuilder } = require('discord.js')
2022-11-27 02:35:28 -05:00
const moment = require('moment-timezone')
2022-08-14 05:51:45 -04:00
module.exports = {
name: 'time',
alias: [],
description: 'Shows the time',
usage: '<timezone>',
trusted: 0,
execute (bot, username, sender, prefix, args, config, hash, ownerhash, selector) {
2022-11-27 02:35:28 -05:00
const timezone = args.join(' ')
if (!moment.tz.names().map((zone) => zone.toLowerCase()).includes(timezone.toLowerCase())) {
2022-11-27 02:35:28 -05:00
throw new SyntaxError('Invalid timezone')
2022-10-14 04:46:41 -04:00
}
const momented = moment().tz(timezone).format('dddd, MMMM Do, YYYY, hh:mm:ss A')
const component = [{ text: 'The current date and time for the timezone ', color: 'white' }, { text: timezone, color: 'aqua' }, { text: ' is: ', color: 'white' }, { text: momented, color: 'green' }]
bot.tellraw(selector, component)
2022-10-14 04:46:41 -04:00
},
discordExecute (bot, username, sender, prefix, args, channeldc, message, config) {
2022-11-27 02:35:28 -05:00
const timezone = args.join(' ')
if (!moment.tz.names().map((zone) => zone.toLowerCase()).includes(timezone.toLowerCase())) {
2022-11-27 02:35:28 -05:00
throw new SyntaxError('Invalid timezone')
2022-08-14 05:51:45 -04:00
}
const momented = moment().tz(timezone).format('dddd, MMMM Do, YYYY, hh:mm:ss A')
const description = `The current date and time for the timezone ${timezone} is: ${momented}`
const Embed = new EmbedBuilder()
.setColor(config.discord.embedsColors.normal)
.setTitle('Time')
.setDescription(description)
channeldc.send({ embeds: [Embed] })
2022-11-27 02:35:28 -05:00
}
}