| ... | ... | @@ -1,7 +1,8 @@ |
| 1 | 1 | import Color from "color"; |
| 2 | 2 | import * as Discord from "discord.js"; |
| 3 | 3 | import NodeCache from "node-cache"; |
| 4 | | |
| 4 | import fs from 'fs'; |
| 5 | import path from 'path'; |
| 5 | 6 | import 'dotenv/config'; |
| 6 | 7 | |
| 7 | 8 | const helpMessage = `**I'm the Name Painter. I let users customize their name color.** |
| ... | ... | @@ -188,9 +189,45 @@ client.on('guildCreate', async(guild) => { |
| 188 | 189 | |
| 189 | 190 | client.login(process.env.TOKEN); |
| 190 | 191 | |
| 191 | | // if (process.env.HEALTHCHECKS_URL) { |
| 192 | | // var https = require('https'); |
| 193 | | // setInterval(() => { |
| 194 | | // https.get(process.env.HEALTHCHECKS_URL).on('error', () => {}); |
| 195 | | // }, 5 * 60 * 1000); |
| 196 | | // } |
| 192 | if (process.env.HEALTHCHECKS_URL) { |
| 193 | var https = require('https'); |
| 194 | setInterval(() => { |
| 195 | https.get(process.env.HEALTHCHECKS_URL).on('error', () => {}); |
| 196 | }, 5 * 60 * 1000); |
| 197 | } |
| 198 | |
| 199 | // Client error handler. |
| 200 | client.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. |
| 212 | client.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.) |
| 224 | client.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 | }); |