discord-active-developer-badge/app.js

42 lines
1.5 KiB
JavaScript
Raw Normal View History

2022-11-11 04:39:20 +07:00
const { createInterface } = require('node:readline');
2022-11-11 07:44:23 +07:00
const { execSync } = require('child_process');
const fetch = require('node-fetch');
const { Client, Routes } = require('discord.js');
2022-11-11 04:39:20 +07:00
2022-11-12 00:58:42 +07:00
const client = new Client({ intents: [] });
2022-11-11 04:39:20 +07:00
const rl = createInterface({ input: process.stdin, output: process.stdout });
client.on('interactionCreate', (interaction) => {
interaction.reply('yes');
});
const question = (q) => new Promise((resolve) => rl.question(q, resolve));
(async ()=>{
const token = await question('Application token? ');
if(!token) throw new Error('Invalid token');
2022-11-11 07:44:23 +07:00
const ratelimitTest = await fetch(`https://discord.com/api/v9/invites/discord-developers`);
if(!ratelimitTest.ok) {
await question(`Uh oh, looks like the node you're on is currently being blocked by Discord. Press the "Enter" button on your keyboard to be reassigned to a new node. (you'll need to rerun the program once you reconnect)`)
// This kills the container manager on the repl forcing Replit to assign the repl to another node with another IP address (if the ip is globally rate limited)
execSync('kill 1');
return;
};
2022-11-11 04:39:20 +07:00
await client.login(token).catch((err) => {
throw err
});
await client.rest.put(Routes.applicationCommands(client.user.id), { body: [
2022-11-11 04:39:20 +07:00
{
name: 'ping',
description: 'yes'
}
] });
2022-11-13 01:39:03 +07:00
console.log('DONE | Application/Bot is up and running. DO NOT CLOSE THIS TAB UNLESS YOU ARE FINISHED USING THE BOT, IT WILL PUT THE BOT OFFLINE.');
2022-11-12 00:58:42 +07:00
})();