From 743337cead85a8da4b68ff8cf8c55ec5381ba4a8 Mon Sep 17 00:00:00 2001 From: Cesium Date: Sun, 9 Nov 2025 20:19:41 -0500 Subject: [PATCH] complain if expected files are not created instead of big confusing error --- index.js | 12 +++++++++--- torn.js | 9 ++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 0877470..8b12c2b 100644 --- a/index.js +++ b/index.js @@ -3,8 +3,14 @@ const fs = require('fs'); const path = require('node:path'); const torn = require('./torn.js'); -const config = require('./config.json'); -const state = require('./state.json'); +let config, state; +try { + config = require('./config.json'); + state = require('./state.json'); +} catch { + console.error("Fatal: Unable to load config.json or state.json. Please follow the instructions in README.md"); + process.exit(1); +} // the basic discord setup stuff yoinked from their guide const { Client, Collection, Events, GatewayIntentBits, EmbedBuilder, Partials, MessageFlags } = require('discord.js'); @@ -22,11 +28,11 @@ const client = new Client({ }); client.once(Events.ClientReady, readyClient => { console.log(`Discord: Connected as ${readyClient.user.tag}`); + torn.readyCheck(config.torn); }); client.login(config.token); client.commands = new Collection(); -torn.readyCheck(config.torn); let task = {}; fs.readdir('./tasks/', (err, files) => { diff --git a/torn.js b/torn.js index 160350f..f25031a 100644 --- a/torn.js +++ b/torn.js @@ -1,4 +1,11 @@ -const config = require('./config') +let config; +try { + config = require('./config') +} catch { + return +} + + module.exports = () => {}; module.exports.readyCheck = async (key) => { const url = `https://api.torn.com/user/?selections=basic&key=${key}`