log errors to discord
This commit is contained in:
parent
6f39c42c7b
commit
02a4a72ddf
|
@ -8,6 +8,7 @@ module.exports = {
|
|||
|
||||
"webhooks": {
|
||||
"welcome": process.env.WEBHOOK_WELCOME.split("/"),
|
||||
"error": process.env.WEBHOOK_ERROR.split("/")
|
||||
},
|
||||
|
||||
"opID": "281134216115257344",
|
||||
|
|
19
src/main.js
19
src/main.js
|
@ -6,6 +6,23 @@ global.Discord = require('discord.js');
|
|||
global.fs = require('fs');
|
||||
global.dClient = new Discord.Client({ disableEveryone: true });
|
||||
|
||||
// error handling
|
||||
{
|
||||
let webhook = new Discord.WebhookClient(config.webhooks.error[0], config.webhooks.error[1]);
|
||||
global.onError = function logError(error) {
|
||||
let msg = error.stack || error.message || error;
|
||||
console.error(msg);
|
||||
try {
|
||||
webhook.send(`\`\`\`\n${msg}\n\`\`\``).catch(()=>{});
|
||||
} catch(e) {}
|
||||
}
|
||||
process.on('unhandledRejection', onError);
|
||||
process.on('uncaughtException', onError);
|
||||
dClient.on('error', onError);
|
||||
dClient.on('warn', onError);
|
||||
}
|
||||
|
||||
|
||||
global.dbClient = new (require('pg').Client)({
|
||||
connectionString: process.env.DATABASE_URL,
|
||||
ssl: !testmode,
|
||||
|
@ -31,5 +48,3 @@ dClient.once('ready', () => {
|
|||
require('./misc');
|
||||
|
||||
});
|
||||
dClient.on('error', console.error);
|
||||
dClient.on('warn', console.warn);
|
|
@ -1,10 +1,3 @@
|
|||
process.on('unhandledRejection', error => {
|
||||
console.error(error.stack);
|
||||
});
|
||||
process.on('uncaughtException', error => {
|
||||
console.error(error.stack);
|
||||
});
|
||||
|
||||
Array.prototype.random = function () {
|
||||
return this[Math.floor(Math.random() * this.length)]
|
||||
}
|
Loading…
Reference in New Issue