From 9580a500fd6d3fbe0efa7f6c8737694fc9a90e80 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Tue, 14 Mar 2023 15:14:29 -0400 Subject: [PATCH] extra tools to use with the bot --- modules/utils.js | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 modules/utils.js diff --git a/modules/utils.js b/modules/utils.js new file mode 100644 index 0000000..fbedd23 --- /dev/null +++ b/modules/utils.js @@ -0,0 +1,58 @@ +/* eslint-disable no-case-declarations */ +/* eslint-disable indent */ +// dotenv for handling environment variables +const dotenv = require('dotenv'); +dotenv.config(); +const token = process.env.TOKEN; + +// Discord.JS +const { Client, GatewayIntentBits, Partials } = require('discord.js'); +const client = new Client({ + intents: [ + GatewayIntentBits.Guilds, + GatewayIntentBits.GuildMessages, + GatewayIntentBits.GuildMessageReactions, + GatewayIntentBits.MessageContent + ], + partials: [ + Partials.Channel, + Partials.Message + ], +}); + +// Various imports +const fn = require('../modules/functions.js'); + +client.once('ready', async () => { + watchRequestRates(); + console.log('Ready!'); + const count = JSON.stringify(client.guilds.cache.size); + console.log(count); +}); + +client.login(token); + + +async function watchRequestRates() { + const axios = require('axios'); + + // Make a GET request to the Discord API + await axios.get('https://discord.com/api/v10/users/@me', { + headers: { + 'Authorization': `Bot ${token}` + } + }).then(response => { + // Get the rate limit headers + const remaining = response.headers['x-ratelimit-remaining']; + const reset = response.headers['x-ratelimit-reset']; + + // Log the rate limit headers + console.log(`Remaining requests: ${remaining}`); + console.log(`Reset time (Unix epoch seconds): ${reset}`); + }).catch(error => { + console.error(error); + }); + await fn.sleep(500).then(async () =>{ + await watchRequestRates(); + }); +} \ No newline at end of file