This repository was archived by the owner on Mar 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathtest.js
More file actions
35 lines (32 loc) · 1.21 KB
/
test.js
File metadata and controls
35 lines (32 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//Import some packages needed
require('dotenv').config();
const moment = require('moment');
const tz = require('moment-timezone');
const chalk = require('chalk');
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
const { TIMEZONE, FORMAT, CHANNEL_ID, UPDATE_INTERVAL, BOT_TOKEN} = process.env;
//'ready' event
client.once('ready', () => {
//init time
const timeNow = moment().tz(TIMEZONE).format(FORMAT);
//define clockChannel
const clockChannel = client.channels.cache.get(CHANNEL_ID);
//initial update
clockChannel.edit({ name: `🕒 ${timeNow}` }, 'Clock update')
.catch(console.error);
//set the interval
setInterval(() => {
const timeNowUpdate = moment().tz(TIMEZONE).format(FORMAT);
clockChannel.edit({ name: `🕒 ${timeNowUpdate}` }, 'Clock update')
.catch(console.error);
}, UPDATE_INTERVAL);
setTimeout(() => {
console.log("Stopping process with the code \"0\"...");
process.exit(0);
}, UPDATE_INTERVAL);
//tells if it is ready
console.log(chalk.greenBright("[READY]"), `Logged in as ${client.user.tag} (${client.user.id}) at ${moment().format("DD MMMM YYYY, HH:mm:ss")}`);
});
//log in
client.login(BOT_TOKEN);