discord-active-developer-badge/index.js

71 lines
3.0 KiB
JavaScript
Raw Permalink 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-17 09:37:22 +07:00
const ping = {
name: 'ping',
description: 'Pings the bot and shows the latency'
2022-11-17 09:37:22 +07:00
};
// Command Example
2022-11-17 09:38:47 +07:00
const command2 = {
name:'command2',
description:'yes'
}
2022-11-17 09:37:22 +07:00
const commands = [ping, command2]; // Add your commands with commas to add them to the bot!
// Join the Discord for support: https://discord.gg/M5MSE9CvNM
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 });
2022-11-17 09:37:22 +07:00
client.on('interactionCreate', (interaction) => {
if (interaction.commandName === 'ping') {
2022-12-02 09:39:31 +07:00
interaction.reply(`Latency is ${Date.now() - interaction.createdTimestamp}ms. API Latency is ${Math.round(client.ws.ping)}ms`);
2022-11-17 09:37:22 +07:00
} else if(interaction.commandName === 'command2') { // This is the example command's name!
interaction.reply('example command');
2022-11-17 09:38:47 +07:00
} else { // a response if you forget to add the command here
2022-11-17 09:37:22 +07:00
interaction.reply('this command\'s response has not been added yet!');
}
2022-11-11 04:39:20 +07:00
});
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)
//^ in short: Restarts the bot to be used again/attempted to start up again!
2022-11-11 07:44:23 +07:00
execSync('kill 1');
return;
};
2022-11-11 04:39:20 +07:00
await client.login(token).catch((err) => {
throw err
});
2022-11-17 09:38:47 +07:00
await client.rest.put(Routes.applicationCommands(client.user.id), { body: commands });
2022-11-11 04:39:20 +07:00
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.');
2023-02-26 06:40:43 +07:00
// Skysilk Sponsorship (feel free to remove this if you're editing the code)
console.log(`\n\n`);
const chalk = require('chalk');
require('console-png').attachTo(console);
console.log(chalk.bold('Sponsored by', chalk.hex('#5A96F6')('SkySilk')));
console.log(`The #1 VPS hosting solution for Discord bots, website, and more.\nChoose from dozens of Linux apps & clean OS installs to deploy in seconds with just 1-click. Whether you're running a small cloud operation or part of an enterprise-level organization, SkySilk offers over 40 resource plans to ensure you have the right cloud VPS environment suitable for your projects.`);
console.log(`----> ${chalk.green.bold(`https://bit.ly/SkysilkBotHosting`)} <----\n`);
2023-10-31 09:55:42 +07:00
console.png(require('path').join(__dirname, 'assets', 'skysilk-logo-icon.png'))
2022-11-12 00:58:42 +07:00
})();