Skip to content

Commit 2b2fa6b

Browse files
author
Elbert-Ainstein
committed
Initial Commit -- Template from my old bot
1 parent 020a88c commit 2b2fa6b

File tree

17 files changed

+2790
-0
lines changed

17 files changed

+2790
-0
lines changed

Diff for: .env

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
TOKEN="MTE1NjM5Mzk3MDE5MzE1MDA3Mg.G73PZx.DLWr_cPpClVJx80qjJuEbSA0oUq-DcfXK0UIcQ"
2+
CLIENTID="1156393970193150072"
3+
DEVID=""

Diff for: .gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/node_modules

Diff for: Buttons/temp.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a temp file, delete once code is downloaded.

Diff for: Commands/Public/ping.js

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
const { ChatInputCommandInteraction, Client, SlashCommandBuilder } = require("discord.js");
2+
3+
module.exports = {
4+
data: new SlashCommandBuilder()
5+
.setName("ping")
6+
.setDescription(`Get the bots Ping`),
7+
/**
8+
*
9+
* @param {ChatInputCommandInteraction} interaction
10+
* @param {Client} client
11+
*/
12+
async execute(interaction, client) {
13+
14+
let e;
15+
16+
if (client.ws.ping <= 185) {
17+
e = `🟢`;
18+
} else if (client.ws.ping <= 250) {
19+
e = `🟠`;
20+
} else {
21+
e = `🔴`;
22+
}
23+
24+
25+
interaction.reply({ content: "Calculating Ping..." })
26+
interaction.fetchReply().then(reply => {
27+
let ping = reply.createdTimestamp - interaction.createdTimestamp;
28+
29+
let f;
30+
31+
if (ping <= 185) {
32+
f = `🟢`;
33+
} else if (ping <= 250) {
34+
f = `🟠`;
35+
} else {
36+
f = `🔴`;
37+
}
38+
39+
interaction.editReply({
40+
content: "",
41+
embeds: [
42+
{
43+
color: parseInt(client.storage.colors.primary),
44+
fields: [{
45+
name: "API Speed",
46+
value: `${e} | ${client.ws.ping}ms`,
47+
inline: true
48+
},
49+
{
50+
name: "Interaction Speed",
51+
value: `${f} | ${ping}ms`,
52+
inline: true
53+
},
54+
{
55+
name: "Uptime",
56+
value: `🔧 | <t:${parseInt(client.readyTimestamp / 1000)}:R>`,
57+
inline: true
58+
}
59+
]
60+
}
61+
]
62+
})
63+
})
64+
}
65+
}

Diff for: Events/Client/ready.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const { Client, ActivityType } = require("discord.js")
2+
const chalk = require("chalk")
3+
const { LoadCommands } = require("../../Handlers/commands");
4+
const { default: mongoose } = require("mongoose");
5+
const cfg = require("../../Storage/config.json");
6+
7+
module.exports = {
8+
name: "ready",
9+
once: true,
10+
/**
11+
*
12+
* @param {Client} client
13+
*/
14+
async execute(client) {
15+
await LoadCommands(client);
16+
client.user.setActivity({
17+
name: `${client.guilds.cache.size} Servers`,
18+
type: ActivityType.Watching
19+
})
20+
21+
console.log(
22+
chalk.yellow("[Client] ") +
23+
chalk.cyanBright(": ") +
24+
chalk.whiteBright(`Client Logged in as `) +
25+
chalk.magenta.bold(`${client.user.tag}`)
26+
);
27+
28+
}
29+
}

Diff for: Events/Interaction/Buttons.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const { ButtonInteraction, Client } = require("discord.js");
2+
3+
module.exports = {
4+
name: "interactionCreate",
5+
/**
6+
*
7+
* @param {ButtonInteraction} interaction
8+
* @param {Client} client
9+
* @returns
10+
*/
11+
async execute(interaction, client) {
12+
if (!interaction.isButton) return;
13+
14+
if (interaction.isButton()) {
15+
var cmd = client.Buttons.get(interaction.customId);
16+
if (cmd)
17+
if (!interaction.member.permissions.has(cmd.userPermissions || [])) {
18+
const UserNoPerms = new EmbedBuilder()
19+
.setColor("Red")
20+
.setDescription(
21+
`You Require **${cmd.userPermissions}** to use this button`
22+
);
23+
return interaction.reply({
24+
embeds: [UserNoPerms],
25+
ephemeral: true,
26+
});
27+
} else if (
28+
!interaction.guild.members.me.permissions.has(cmd.botPermissions || [])
29+
) {
30+
const BotNoPerms = new EmbedBuilder()
31+
.setColor("Red")
32+
.setDescription(
33+
`I Require **${cmd.botPermissions}** to execute this interaction`
34+
);
35+
36+
return interaction.reply({
37+
embeds: [BotNoPerms],
38+
ephemeral: true,
39+
});
40+
} else {
41+
cmd.execute(interaction, client);
42+
}
43+
}
44+
}
45+
}

Diff for: Events/Interaction/SlashCommands.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const { Client, ChatInputCommandInteraction } = require("discord.js");
2+
3+
module.exports = {
4+
name: "interactionCreate",
5+
/**
6+
*
7+
* @param {ChatInputCommandInteraction} interaction
8+
* @param {Client} client
9+
*/
10+
async execute (interaction, client) {
11+
if (!interaction.isChatInputCommand()) return;
12+
13+
const command = client.commands.get(interaction.commandName);
14+
if (!command)
15+
return interaction.reply({
16+
content: "This command is outdated.",
17+
ephemeral: true
18+
});
19+
20+
if (command.developer && interaction.user.id !== client.config.DeveloperID)
21+
return interaction.reply({
22+
content: "This command is restricted to developers only.",
23+
ephemeral: true
24+
});
25+
26+
command.execute(interaction, client);
27+
}
28+
}

Diff for: Functions/FileLoader.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const { glob } = require("glob");
2+
const { promisify } = require("util");
3+
const proGlob = promisify(glob);
4+
5+
async function loadFiles(dirName) {
6+
const Files = await proGlob(`${process.cwd().replace(/\\/g, "/")}/${dirName}/**/*.js`);
7+
Files.forEach((file) => delete require.cache[require.resolve(file)]);
8+
return Files;
9+
};
10+
11+
module.exports = { loadFiles }

Diff for: Handlers/Buttons.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const { resolve } = require("path");
2+
const { readdir } = require("fs").promises;
3+
const { EmbedBuilder } = require("discord.js");
4+
const chalk = require("chalk");
5+
module.exports = (client) => {
6+
async function getFiles(dir) {
7+
const dirents = await readdir(dir, { withFileTypes: true });
8+
const files = await Promise.all(
9+
dirents.map((dirent) => {
10+
const res = resolve(dir, dirent.name);
11+
return dirent.isDirectory() ? getFiles(res) : res;
12+
})
13+
);
14+
return Array.prototype.concat(...files);
15+
}
16+
17+
async function run() {
18+
const files = await getFiles("./Buttons/");
19+
const jsFiles = files.filter((f) => f.split(`.`).pop() === "js");
20+
if (jsFiles.length <= 0)
21+
return console.log(
22+
chalk.yellowBright.bold(`[Button-Handler] No loadable Buttons detected`)
23+
);
24+
console.log(
25+
chalk.blueBright.bold(
26+
`[Button-Handler]: Loaded ${jsFiles.length} Buttons`
27+
)
28+
);
29+
30+
jsFiles.forEach((fileName, index) => {
31+
let props = require(fileName);
32+
client.Buttons.set(props.custom_id, props);
33+
});
34+
}
35+
run()
36+
}

Diff for: Handlers/commands.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const { Client, REST, Routes } = require("discord.js");
2+
const { loadFiles } = require("../Functions/FileLoader");
3+
const ascii = require("ascii-table");
4+
const chalk = require("chalk")
5+
6+
/**
7+
* @param {Client} client
8+
*/
9+
async function LoadCommands(client) {
10+
11+
const table = new ascii().setHeading("Command", "Status");
12+
13+
await client.commands.clear();
14+
15+
let CommandsArray = [];
16+
17+
const Files = await loadFiles("Commands");
18+
19+
Files.forEach((file) => {
20+
const command = require(file);
21+
client.commands.set(command.data.name, command);
22+
23+
CommandsArray.push(command.data.toJSON());
24+
25+
table.addRow(command.data.name, "💚");
26+
});
27+
28+
client.application.commands.set(CommandsArray);
29+
30+
return console.log(chalk.whiteBright(table.toString()),
31+
chalk.blue("\n[Commands] ") +
32+
chalk.cyanBright(": ") +
33+
chalk.whiteBright("Loaded Commands.")
34+
);
35+
}
36+
37+
module.exports = { LoadCommands };

Diff for: Handlers/events.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const { loadFiles } = require("../Functions/FileLoader");
2+
const ascii = require("ascii-table");
3+
const chalk = require("chalk");
4+
5+
async function LoadEvents(client) {
6+
const table = new ascii();
7+
table.setHeading("Event", "Status");
8+
9+
await client.events.clear();
10+
11+
const files = await loadFiles("Events");
12+
13+
files.forEach((file) => {
14+
const event = require(file);
15+
const execute = (...args) => event.execute(...args, client);
16+
17+
client.events.set(event.name, execute);
18+
19+
if (event.rest) {
20+
if (event.once) client.rest.once(event.name, execute);
21+
else
22+
client.rest.on(event.name, execute);
23+
} else {
24+
if (event.once) client.once(event.name, execute);
25+
else
26+
client.on(event.name, execute);
27+
};
28+
29+
table.addRow(event.name, "💚");
30+
});
31+
32+
console.log(chalk.whiteBright(table.toString()),
33+
chalk.blue("\n[Events] ") +
34+
chalk.cyanBright(": ") +
35+
chalk.whiteBright("Loaded Events.")
36+
);
37+
}
38+
39+
module.exports = { LoadEvents }

Diff for: Storage/ClientStorage.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"colors": {
3+
"red": "0xFF5356",
4+
"primary": "0x2981b3",
5+
"green": "0x00FF7A",
6+
"invisible": "0x2f3136"
7+
}
8+
}

Diff for: Storage/config.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"token": "MTE1NjM5Mzk3MDE5MzE1MDA3Mg.G73PZx.DLWr_cPpClVJx80qjJuEbSA0oUq-DcfXK0UIcQ",
3+
"clientId": "1156393970193150072",
4+
"DeveloperID": "Your user id here"
5+
}

Diff for: main.js

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const { Partials, Client, GatewayIntentBits, Collection, ClientPresence, EmbedBuilder, Colors, ButtonInteraction } = require("discord.js");
2+
const { LoadEvents } = require("./Handlers/events");
3+
4+
const client = new Client({
5+
intents: [
6+
GatewayIntentBits.Guilds,
7+
GatewayIntentBits.GuildMessages,
8+
GatewayIntentBits.MessageContent,
9+
GatewayIntentBits.GuildMembers,
10+
GatewayIntentBits.DirectMessages
11+
],
12+
partials: [
13+
Partials.Channel,
14+
Partials.GuildMember,
15+
Partials.Message,
16+
Partials.ThreadMember,
17+
Partials.User,
18+
],
19+
});
20+
21+
client.config = require("./Storage/config.json")
22+
client.storage = require("./Storage/ClientStorage.json");
23+
24+
client.events = new Collection();
25+
client.commands = new Collection();
26+
client.Buttons = new Collection();
27+
28+
LoadEvents(client);
29+
require("./Handlers/Buttons")(client);
30+
31+
module.exports = { client };
32+
33+
const buttonHandlers = {};
34+
35+
global.handleButton = (id, cb) => {
36+
buttonHandlers[id] = cb;
37+
return { remove: () => delete buttonHandlers[id] };
38+
};
39+
40+
client.on("interactionCreate", i => {
41+
if (i instanceof ButtonInteraction) {
42+
if (buttonHandlers[i.customId]) buttonHandlers[i.customId](i, client);
43+
}
44+
});
45+
46+
client.login(client.config.token);

0 commit comments

Comments
 (0)