-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
108 lines (90 loc) · 3.76 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import chalk from "chalk";
import { Client, EmbedBuilder } from "discord.js";
import fetch from "node-fetch";
import ora from "ora";
import prompts from "prompts";
console.log(chalk.bold.green("Discord Active Developer Badge"));
console.log(chalk.bold(chalk.red("Remember to do not share your Discord Bot token with anyone!\n")));
console.log(chalk.bold("This tool will help you to get the " + chalk.cyan.underline("Discord Active Developer Badge")));
console.log(chalk.bold("If you have any problem, please contact me on Discord: " + chalk.cyan.underline("majonez.exe") + "\n"));
export async function checkToken(value: string): Promise<boolean> {
if (!value) return false;
const res = await fetch("https://discord.com/api/v10/users/@me", {
method: "GET",
headers: {
Authorization: `Bot ${value.toString()}`,
},
});
return res.status !== 200 ? false : true;
}
const community = await prompts({
type: "confirm",
name: "value",
message: "You created new Discord Server and enabled Community in Server Settings?",
initial: true,
});
if (!community.value) {
console.log(chalk.bold.red("✖ You need to create new Discord Server and enable Community in Server Settings!"));
/* eslint-disable-next-line node/no-process-exit */
process.exit(0);
}
const tokenPrompt = await prompts({
type: "password",
name: "token",
message: "Enter your Discord Bot token",
validate: async (value: string) => {
const valid = await checkToken(value);
return valid ? true : "Invalid Discord Bot token!";
},
});
const valid = await checkToken(tokenPrompt.token);
if (!valid) {
console.log(chalk.bold.red("✖ Invalid Discord Bot token!"));
/* eslint-disable-next-line node/no-process-exit */
process.exit(0);
}
console.log();
const spinner = ora(chalk.bold("Running Discord Bot")).start();
const client = new Client({
intents: [],
});
try {
client.login(tokenPrompt.token);
} catch (_e) {
spinner.fail(chalk.bold("Error while logging in to Discord! GG, You broke Discord!"));
/* eslint-disable-next-line node/no-process-exit */
process.exit(0);
}
const slashSpinner = ora(chalk.bold("Creating slash command interaction..."));
client.on("ready", async (client) => {
spinner.succeed(chalk.bold(`Logged in as ${chalk.cyan.underline(client.user.tag)}!`));
console.log(chalk.bold.green("✔") + chalk.bold(" Use this link to add your bot to your server: " + chalk.cyan.italic.underline(`https://discord.com/api/oauth2/authorize?client_id=${client.user.id}&scope=applications.commands%20bot\n`)));
slashSpinner.start();
await client.application?.commands.set([
{
name: "active",
description: "Get the Discord Active Developer Badge",
},
]);
slashSpinner.text = chalk.bold("Go to your Discord Server (where you added your bot) and use the slash command " + chalk.cyan.bold("/active"));
slashSpinner.start();
});
client.on("interactionCreate", async (interaction) => {
if (!interaction.isCommand()) return;
if (interaction.commandName === "active") {
const embed = new EmbedBuilder() // prettier
.setAuthor({
name: "Discord Active Developer Badge",
iconURL: "https://cdn.discordapp.com/emojis/1040325165512396830.webp?size=64&quality=lossless",
})
.setTitle("You have successfully ran the slash command!")
.setColor("#34DB98")
.setDescription("- Go to *https://discord.com/developers/active-developer* and claim your badge\n - Verification can take up to 24 hours, so wait patiently until you get your badge")
.setFooter({
text: "Made by @majonez.exe",
iconURL: "https://cdn.discordapp.com/emojis/1040325165512396830.webp?size=64&quality=lossless",
});
slashSpinner.succeed(chalk.bold("You have successfully ran the slash command! Follow the instructions in Discord Message that you received!"));
await interaction.reply({ embeds: [embed], ephemeral: true });
}
});