authorgravatar for git@paperclover.netclover caruso <git@paperclover.net> 2023-04-06 22:20:04+00:00
committergravatar for git@paperclover.netclover caruso <git@paperclover.net> 2026-01-02 23:03:55-08:00
log9ae9951e345bd662bd9ea335e6a6c91a58fc455c
tree69a44f424860556532ed002051621e66a720b3a5
parentad56923db67573635b04eecfd11feabe84447d1c
signaturelock-open Commit is signed but in an unrecognized format.

Add error handling stuff from @Toshizuno


1 files changed, 44 insertions(+), 7 deletions(-)

index.ts+44-7
...@@ -1,7 +1,8 @@...@@ -1,7 +1,8 @@
1import Color from "color";1import Color from "color";
2import * as Discord from "discord.js";2import * as Discord from "discord.js";
3import NodeCache from "node-cache";3import NodeCache from "node-cache";
44import fs from 'fs';
5import path from 'path';
5import 'dotenv/config';6import 'dotenv/config';
67
7const helpMessage = `**I'm the Name Painter. I let users customize their name color.**8const helpMessage = `**I'm the Name Painter. I let users customize their name color.**
...@@ -188,9 +189,45 @@ client.on('guildCreate', async(guild) => {...@@ -188,9 +189,45 @@ client.on('guildCreate', async(guild) => {
188189
189client.login(process.env.TOKEN);190client.login(process.env.TOKEN);
190191
191// if (process.env.HEALTHCHECKS_URL) {192if (process.env.HEALTHCHECKS_URL) {
192// var https = require('https');193 var https = require('https');
193// setInterval(() => {194 setInterval(() => {
194// https.get(process.env.HEALTHCHECKS_URL).on('error', () => {});195 https.get(process.env.HEALTHCHECKS_URL).on('error', () => {});
195// }, 5 * 60 * 1000);196 }, 5 * 60 * 1000);
196// }197}
198
199// Client error handler.
200client.on('error', function (error) {
201 // Writes a log of what happened to a log file.
202 fs.writeFileSync(
203 path.join('logs', `${Date.now()}.err`),
204 `${error.name}: ${error.message}`
205 );
206
207 // Exits the process (and hopefully restarts!)
208 process.exit();
209});
210
211// Invalidation handler.
212client.on('invalidated', function () {
213 // Writes a log of what happened to a log file.
214 fs.writeFileSync(
215 path.join('logs', `${Date.now()}.inv`),
216 'Error: The client was invalidated by Discord.'
217 );
218
219 // Exits the process (and hopefully restarts!)
220 process.exit();
221});
222
223// Client warning handler (which might not require restarting but just to be safe.)
224client.on('error', function (info) {
225 // Writes a log of what happened to a log file.
226 fs.writeFileSync(
227 path.join('logs', `${Date.now()}.warn`),
228 `Warning: ${info}`
229 );
230
231 // Exits the process (and hopefully restarts!)
232 process.exit();
233});