|
| 1 | +require('dotenv') |
| 2 | + .config(); |
| 3 | + |
| 4 | +const { |
| 5 | + WebhookClient, |
| 6 | + MessageEmbed, |
| 7 | +} = require('discord.js'); |
| 8 | + |
| 9 | +const { inspect } = require('util'); |
| 10 | + |
| 11 | +const warnWebhook = new WebhookClient({ |
| 12 | + url: process.env.WARNWEBHOOKURL, |
| 13 | +}); |
| 14 | +const errorWebhook = new WebhookClient({ |
| 15 | + url: process.env.ERRORWEBHOOKURL, |
| 16 | +}); |
| 17 | + |
| 18 | +module.exports = (client) => { |
| 19 | + client.on('debug', (e) => { |
| 20 | + if (!e.includes('ratelimit')) return; |
| 21 | + |
| 22 | + console.log('[BOT] Watch-out Possible Rate-limit...\n', e); |
| 23 | + const embed = new MessageEmbed() |
| 24 | + .setTitle('Watch-out Possible Rate-limit...') |
| 25 | + .addFields([{ |
| 26 | + name: 'Info', |
| 27 | + value: `\`\`\`${inspect(e, { depth: 0 })}\`\`\``, |
| 28 | + }]) |
| 29 | + .setTimestamp(); |
| 30 | + |
| 31 | + warnWebhook |
| 32 | + .send({ |
| 33 | + embeds: [embed], |
| 34 | + }) |
| 35 | + .catch((err) => { |
| 36 | + }); |
| 37 | + }); |
| 38 | + |
| 39 | + client.on('error', (e) => { |
| 40 | + console.log('[BOT] Bot got a error...\n\n', e); |
| 41 | + const embed = new MessageEmbed() |
| 42 | + .setTitle('Bot got a error...') |
| 43 | + .addFields([{ |
| 44 | + name: 'Error', |
| 45 | + value: `\`\`\`${inspect(e, { depth: 0 })}\`\`\``, |
| 46 | + }]) |
| 47 | + .setTimestamp(); |
| 48 | + |
| 49 | + errorWebhook |
| 50 | + .send({ |
| 51 | + embeds: [embed], |
| 52 | + }) |
| 53 | + .catch((err) => { |
| 54 | + }); |
| 55 | + }); |
| 56 | + |
| 57 | + client.on('warn', async (info) => { |
| 58 | + console.log('[BOT] Bot got a warn...\n\n', info); |
| 59 | + const embed = new MessageEmbed() |
| 60 | + .setTitle('Bot got a warn...') |
| 61 | + .addFields([{ |
| 62 | + name: 'Info', |
| 63 | + value: `\`\`\`${inspect(info, { depth: 0 })}\`\`\``, |
| 64 | + }]) |
| 65 | + .setTimestamp(); |
| 66 | + |
| 67 | + warnWebhook |
| 68 | + .send({ |
| 69 | + embeds: [embed], |
| 70 | + }) |
| 71 | + .catch((err) => { |
| 72 | + }); |
| 73 | + }); |
| 74 | + |
| 75 | + process.on('unhandledRejection', async (reason, p) => { |
| 76 | + console.log('[BOT | FATAL ERROR] Unhandled Rejection/Catch'); |
| 77 | + console.log(reason, p); |
| 78 | + |
| 79 | + const embed = new MessageEmbed() |
| 80 | + .setTitle('New Unhandled Rejection/Catch') |
| 81 | + .setDescription(`\`\`\`${reason}\`\`\``) |
| 82 | + .setColor('#4E5D94') |
| 83 | + .addFields([ |
| 84 | + { |
| 85 | + name: 'Reason', |
| 86 | + value: `\`\`\`${inspect(reason, { depth: 0 })}\`\`\``, |
| 87 | + }, |
| 88 | + { |
| 89 | + name: 'Promise', |
| 90 | + value: `\`\`\`${inspect(p, { depth: 0 })}\`\`\``, |
| 91 | + }, |
| 92 | + ]) |
| 93 | + .setTimestamp(); |
| 94 | + |
| 95 | + errorWebhook |
| 96 | + .send({ |
| 97 | + embeds: [embed], |
| 98 | + }) |
| 99 | + .catch((err) => { |
| 100 | + }); |
| 101 | + }); |
| 102 | + |
| 103 | + process.on('uncaughtException', async (err, origin) => { |
| 104 | + console.log('[BOT | FATAL ERROR] Uncaught Exception/Catch'); |
| 105 | + console.log(err, origin); |
| 106 | + |
| 107 | + const embed = new MessageEmbed() |
| 108 | + .setTitle('New uncaughtException') |
| 109 | + .setDescription(`\`\`\`${err}\`\`\``) |
| 110 | + .setColor('#4E5D94') |
| 111 | + .addFields([ |
| 112 | + { |
| 113 | + name: 'Error', |
| 114 | + value: `\`\`\`${inspect(err, { depth: 0 })}\`\`\``, |
| 115 | + }, |
| 116 | + { |
| 117 | + name: 'Origin', |
| 118 | + value: `\`\`\`${inspect(origin, { depth: 0 })}\`\`\``, |
| 119 | + }, |
| 120 | + ]) |
| 121 | + .setTimestamp(); |
| 122 | + |
| 123 | + errorWebhook |
| 124 | + .send({ |
| 125 | + embeds: [embed], |
| 126 | + }) |
| 127 | + .catch((err) => { |
| 128 | + }); |
| 129 | + }); |
| 130 | + process.on('uncaughtExceptionMonitor', async (err, origin) => { |
| 131 | + console.log('[BOT | FATAL ERROR] Uncaught Exception/Catch (MONITOR)'); |
| 132 | + console.log(err, origin); |
| 133 | + |
| 134 | + const embed = new MessageEmbed() |
| 135 | + .setTitle('New uncaughtExceptionMonitor' + `${global?.CustomBot ? ' (Custom Bot)' : ''}`) |
| 136 | + .setDescription(`\`\`\`${err}\`\`\``) |
| 137 | + .setColor('#4E5D94') |
| 138 | + .addFields([ |
| 139 | + { |
| 140 | + name: 'Error', |
| 141 | + value: `\`\`\`${inspect(err, { depth: 0 })}\`\`\``, |
| 142 | + }, |
| 143 | + { |
| 144 | + name: 'Origin', |
| 145 | + value: `\`\`\`${inspect(origin, { depth: 0 })}\`\`\``, |
| 146 | + }, |
| 147 | + ]) |
| 148 | + .setTimestamp(); |
| 149 | + |
| 150 | + errorWebhook |
| 151 | + .send({ |
| 152 | + embeds: [embed], |
| 153 | + }) |
| 154 | + .catch((err) => { |
| 155 | + }); |
| 156 | + }); |
| 157 | +}; |
0 commit comments