Skip to content

Commit

Permalink
Uploaded Files
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalcodez authored Dec 25, 2021
0 parents commit 4b306cc
Show file tree
Hide file tree
Showing 17 changed files with 1,819 additions and 0 deletions.
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<h1 align="center"> Discord.js v13 Handler With Mango Db </h1>
<p align="center">
<a href="https://github.com/VishalCodez/Discord.js-v13-Handler-With-Mango-Db"><img alt="GitHub Stars" src="https://img.shields.io/github/stars/Simpleboy353/REAPER-2.0?style=for-the-badge"></a>
<a href="https://github.com/VishalCodez/Discord.js-v13-Handler-With-Mango-Db/network"><img alt="GitHub Forks" src="https://img.shields.io/github/forks/Simpleboy353/REAPER-2.0?style=for-the-badge"></a>

</p>

***


## Installation Guide & Requirements


**1.** Install [NodeJS v16.6 or Higher](https://nodejs.org/en/) or Higher
- Discord.js v13 (`npm install discord.js@latest`)
- `applications.commands` Must Check Scope Enabled For Your Bot in Developer Portal (For Slash Commands)
- Basic knowledge of JS or Discord.JS

**2.** Download This Repo And Unzip it | or Git Clone it

**3.** Fill Everything in **`.env`**

**4.** After Fill .env run **`setup.bat`**

**5.** Run Bot Siply With **`start.bat`**
<br/>

## Configuration
- **Modify The `.env` File And Enter The Required Values**
```javascript
DISCORD_TOKEN = BOT TOKEN HERE
MONGODB_SRV = YOUR MANGO DB URL
```
## Made With Hate 😈 By [VIshal Codez](https://github.com/VishalCodez)

22 changes: 22 additions & 0 deletions commands/ping.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { MessageEmbed } = require('discord.js');
module.exports = {
name: "ping",
description: "check bot ping",

async execute(interaction) {
const embed = new MessageEmbed()
.setTitle(`${interaction.client.user.username} Ping`)
.setDescription(`Pong ${Math.round(interaction.client.user.client.ws.ping)} Ms`)
.setColor("RANDOM")
interaction.reply({ embeds: [embed] });
}
};

/**
* @INFO
* Coded By Vishal Codez
* @INFO
* Please Don't Forget To Give Credits To Vishal Codez if You Are Using This
* @INFO
* Please Mention Vishal Codez / In Code Streakers, When Using This Code!
*/
28 changes: 28 additions & 0 deletions commands/uptime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const { MessageEmbed } = require('discord.js');
const moment = require('moment');
module.exports = {
name: "uptime",
description: "bot uptime",

execute(interaction) {
const d = moment.duration(interaction.client.uptime);
const days = (d.days() == 1) ? `${d.days()} Day` : `${d.days()} Days`;
const hours = (d.hours() == 1) ? `${d.hours()} Hour` : `${d.hours()} Hours`;
const minutes = (d.minutes() == 1) ? `${d.minutes()} Minute` : `${d.minutes()} Minutes`;
const seconds = (d.seconds() == 1) ? `${d.seconds()} Second` : `${d.seconds()} Seconds`;
const date = moment().subtract(d, 'ms').format('dddd, MMMM Do YYYY');
const embed = new MessageEmbed()
.setTitle(`${interaction.client.user.username} Uptime`)
.setDescription(`\`\`\`prolog\n${days}, ${hours}, ${minutes}, and ${seconds}\`\`\``)
.setColor("RANDOM")
interaction.reply({ embeds: [embed] });
}
};
/**
* @INFO
* Coded By Vishal Codez
* @INFO
* Please Don't Forget To Give Credits To Vishal Codez if You Are Using This
* @INFO
* Please Mention Vishal Codez / In Code Streakers, When Using This Code!
*/
26 changes: 26 additions & 0 deletions events/client/ready.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// importing logger
const Logger = require("../../lib/logger");

// defining ready event function
const readyEvent = (client) => {
Logger.info(
`Logged in as ${client.user.username}. Ready on ${client.guilds.cache.size} servers, for a total of ${client.users.cache.size} users`
);

client.user.setActivity(
`${client.guilds.cache.size} Servers`,
{
type: "WATCHING",
}
);
};

module.exports = readyEvent;
/**
* @INFO
* Coded By Vishal Codez
* @INFO
* Please Don't Forget To Give Credits To Vishal Codez if You Are Using This
* @INFO
* Please Mention Vishal Codez / In Code Streakers, When Using This Code!
*/
22 changes: 22 additions & 0 deletions events/guild/interactionCreate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const Logger = require("../../lib/logger");
module.exports = async (client, interaction) => {
if (interaction.isCommand()) {
const command = client.slashCommands.get(interaction.commandName);

try {
command.execute(interaction, interaction.options, client);
} catch (err) {
Logger.error(err);
}
} else {
return interaction.followUp({ content: "An error has occurred!" });
}
};
/**
* @INFO
* Coded By Vishal Codez
* @INFO
* Please Don't Forget To Give Credits To Vishal Codez if You Are Using This
* @INFO
* Please Mention Vishal Codez / In Code Streakers, When Using This Code!
*/
28 changes: 28 additions & 0 deletions handlers/eventHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// importing required modules
const fs = require("fs");

// defining event handler
const eventHandler = (client) => {
const load_dir = (dir) => {
const event_files = fs
.readdirSync(`./events/${dir}`)
.filter((file) => file.endsWith(".js"));

for (const file of event_files) {
const event = require(`../events/${dir}/${file}`);
const event_name = file.split(".")[0];
client.on(event_name, event.bind(null, client));
}
};
["client", "guild"].forEach((e) => load_dir(e));
};

module.exports = eventHandler;
/**
* @INFO
* Coded By Vishal Codez
* @INFO
* Please Don't Forget To Give Credits To Vishal Codez if You Are Using This
* @INFO
* Please Mention Vishal Codez / In Code Streakers, When Using This Code!
*/
42 changes: 42 additions & 0 deletions handlers/slashCommandHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// importing required modules
const fs = require("fs");

// importing logger
const Logger = require("../lib/logger");

// defining slash command handler
const slashCommandHandler = async (client) => {
const arrayOfSlashCommand = [];
const command_files = fs
.readdirSync(`./commands/`)
.filter((file) => file.endsWith(".js"));
for (const file of command_files) {
const command = require(`../commands/${file}`);
if (command.name) {
client.slashCommands.set(command.name, command);
arrayOfSlashCommand.push(command);
} else {
continue;
}

client.on("ready", async () => {
try {
Logger.debug("Refreshing slash commands...");
await client.application.commands.set(arrayOfSlashCommand);
Logger.debug("Successfully reloaded slash commands.");
} catch (error) {
Logger.error(error);
}
});
}
};

module.exports = slashCommandHandler;
/**
* @INFO
* Coded By Vishal Codez
* @INFO
* Please Don't Forget To Give Credits To Vishal Codez if You Are Using This
* @INFO
* Please Mention Vishal Codez / In Code Streakers, When Using This Code!
*/
77 changes: 77 additions & 0 deletions lib/logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
const winston = require("winston");
// Define severity levels.
const levels = {
error: 0,
warn: 1,
info: 2,
http: 3,
debug: 4,
};

// This method set the current severity based on
// the current NODE_ENV: show all the log levels
// if the server was run in development mode; otherwise,
// if it was run in production, show only warn and error messages.
const level = () => {
const env = process.env.NODE_ENV || "development";
const isDevelopment = env === "development";
return isDevelopment ? "debug" : "warn";
};

// Define different colors for each level.
const colors = {
error: "red",
warn: "yellow",
info: "cyan",
debug: "white",
};

// Tell winston to add color
winston.addColors(colors);

// Define log format.
const format = winston.format.combine(
// write error stack
winston.format.errors({ stack: true }),
// Add the message timestamp with the preferred format
winston.format.timestamp({ format: "DD-MM-YYYY HH:mm:ss:ms" }),
// log must be colored
winston.format.colorize({ all: true }),
// Defining the format of the message showing the level, the timestamp, and the message
winston.format.printf(
(info) =>
`${info.level} - ${info.timestamp} : ${info.message} ${info.stack || ""}`
)
);

// Defining which transports the logger must use to print out messages.
const transports = [
// Writing error messages in console
new winston.transports.Console(),
// Writing all the error messages in error.log file inside logs folder
new winston.transports.File({
filename: "logs/error.log",
level: "error",
}),
// Writing all the logs in all.log file inside logs folder
new winston.transports.File({ filename: "logs/all.log" }),
];

// Create the logger instance that has to be exported
// and used to log messages.
const Logger = winston.createLogger({
level: level(),
levels,
format,
transports,
});

module.exports = Logger;
/**
* @INFO
* Coded By Vishal Codez
* @INFO
* Please Don't Forget To Give Credits To Vishal Codez if You Are Using This
* @INFO
* Please Mention Vishal Codez / In Code Streakers, When Using This Code!
*/
74 changes: 74 additions & 0 deletions logs/all.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
info - 26-12-2021 01:52:31:5231 : Logged in as Testing Robot. Ready on 4 servers, for a total of 2 users
debug - 26-12-2021 01:52:31:5231 : Refreshing slash commands...
debug - 26-12-2021 01:52:31:5231 : Refreshing slash commands...
debug - 26-12-2021 01:52:32:5232 : Successfully reloaded slash commands.
debug - 26-12-2021 01:52:32:5232 : Successfully reloaded slash commands.
info - 26-12-2021 01:52:32:5232 : connected to the database successfully
info - 26-12-2021 01:53:05:535 : Logged in as Testing Robot. Ready on 4 servers, for a total of 2 users
debug - 26-12-2021 01:53:05:535 : Refreshing slash commands...
debug - 26-12-2021 01:53:05:535 : Refreshing slash commands...
info - 26-12-2021 01:53:07:537 : connected to the database successfully
debug - 26-12-2021 01:53:32:5332 : Successfully reloaded slash commands.
debug - 26-12-2021 01:53:33:5333 : Successfully reloaded slash commands.
error - 26-12-2021 01:56:30:5630 : Invalid connection string "MANGO DB URL" MongoParseError: Invalid connection string "MANGO DB URL"
at new ConnectionString (C:\Users\Vishal\Desktop\Discord.js-v13-Handler With Mango Db\node_modules\mongodb-connection-string-url\lib\index.js:82:19)
at parseOptions (C:\Users\Vishal\Desktop\Discord.js-v13-Handler With Mango Db\node_modules\mongodb\lib\connection_string.js:213:17)
at new MongoClient (C:\Users\Vishal\Desktop\Discord.js-v13-Handler With Mango Db\node_modules\mongodb\lib\mongo_client.js:62:63)
at C:\Users\Vishal\Desktop\Discord.js-v13-Handler With Mango Db\node_modules\mongoose\lib\connection.js:779:16
at new Promise (<anonymous>)
at NativeConnection.Connection.openUri (C:\Users\Vishal\Desktop\Discord.js-v13-Handler With Mango Db\node_modules\mongoose\lib\connection.js:776:19)
at C:\Users\Vishal\Desktop\Discord.js-v13-Handler With Mango Db\node_modules\mongoose\lib\index.js:332:10
at C:\Users\Vishal\Desktop\Discord.js-v13-Handler With Mango Db\node_modules\mongoose\lib\helpers\promiseOrCallback.js:32:5
at new Promise (<anonymous>)
at promiseOrCallback (C:\Users\Vishal\Desktop\Discord.js-v13-Handler With Mango Db\node_modules\mongoose\lib\helpers\promiseOrCallback.js:31:10)
info - 26-12-2021 01:57:08:578 : Logged in as Testing Robot. Ready on 4 servers, for a total of 2 users
debug - 26-12-2021 01:57:08:578 : Refreshing slash commands...
debug - 26-12-2021 01:57:08:578 : Refreshing slash commands...
debug - 26-12-2021 01:57:09:579 : Successfully reloaded slash commands.
debug - 26-12-2021 01:57:09:579 : Successfully reloaded slash commands.
info - 26-12-2021 01:57:09:579 : connected to the database successfully
info - 26-12-2021 02:10:18:1018 : Logged in as Testing Robot. Ready on 4 servers, for a total of 2 users
debug - 26-12-2021 02:10:18:1018 : Refreshing slash commands...
debug - 26-12-2021 02:10:18:1018 : Refreshing slash commands...
debug - 26-12-2021 02:10:19:1019 : Successfully reloaded slash commands.
debug - 26-12-2021 02:10:19:1019 : Successfully reloaded slash commands.
info - 26-12-2021 02:10:19:1019 : connected to the database successfully
error - 26-12-2021 02:10:29:1029 : name is not defined ReferenceError: name is not defined
at Object.execute (C:\Users\Vishal\Desktop\Discord.js-v13-Handler With Mango Db\commands\uptime.js:15:16)
at module.exports (C:\Users\Vishal\Desktop\Discord.js-v13-Handler With Mango Db\events\guild\interactionCreate.js:7:15)
at Client.emit (node:events:390:28)
at InteractionCreateAction.handle (C:\Users\Vishal\Desktop\Discord.js-v13-Handler With Mango Db\node_modules\discord.js\src\client\actions\InteractionCreate.js:73:12)
at Object.module.exports [as INTERACTION_CREATE] (C:\Users\Vishal\Desktop\Discord.js-v13-Handler With Mango Db\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (C:\Users\Vishal\Desktop\Discord.js-v13-Handler With Mango Db\node_modules\discord.js\src\client\websocket\WebSocketManager.js:350:31)
at WebSocketShard.onPacket (C:\Users\Vishal\Desktop\Discord.js-v13-Handler With Mango Db\node_modules\discord.js\src\client\websocket\WebSocketShard.js:443:22)
at WebSocketShard.onMessage (C:\Users\Vishal\Desktop\Discord.js-v13-Handler With Mango Db\node_modules\discord.js\src\client\websocket\WebSocketShard.js:300:10)
at WebSocket.onMessage (C:\Users\Vishal\Desktop\Discord.js-v13-Handler With Mango Db\node_modules\ws\lib\event-target.js:199:18)
at WebSocket.emit (node:events:390:28)
info - 26-12-2021 02:23:34:2334 : Logged in as Testing Robot. Ready on 4 servers, for a total of 2 users
debug - 26-12-2021 02:23:34:2334 : Refreshing slash commands...
debug - 26-12-2021 02:23:34:2334 : Refreshing slash commands...
debug - 26-12-2021 02:23:34:2334 : Successfully reloaded slash commands.
debug - 26-12-2021 02:23:35:2335 : Successfully reloaded slash commands.
info - 26-12-2021 02:23:36:2336 : connected to the database successfully
info - 26-12-2021 02:24:57:2457 : Logged in as Testing Robot. Ready on 4 servers, for a total of 2 users
debug - 26-12-2021 02:24:57:2457 : Refreshing slash commands...
debug - 26-12-2021 02:24:57:2457 : Refreshing slash commands...
debug - 26-12-2021 02:24:57:2457 : Successfully reloaded slash commands.
debug - 26-12-2021 02:24:58:2458 : Successfully reloaded slash commands.
info - 26-12-2021 02:24:58:2458 : connected to the database successfully
info - 26-12-2021 02:25:06:256 : Logged in as Testing Robot. Ready on 4 servers, for a total of 2 users
debug - 26-12-2021 02:25:06:256 : Refreshing slash commands...
debug - 26-12-2021 02:25:06:256 : Refreshing slash commands...
info - 26-12-2021 02:25:07:257 : connected to the database successfully
info - 26-12-2021 02:25:49:2549 : Logged in as Testing Robot. Ready on 4 servers, for a total of 2 users
debug - 26-12-2021 02:25:49:2549 : Refreshing slash commands...
debug - 26-12-2021 02:25:49:2549 : Refreshing slash commands...
info - 26-12-2021 02:25:50:2550 : connected to the database successfully
debug - 26-12-2021 02:25:58:2558 : Successfully reloaded slash commands.
debug - 26-12-2021 02:25:58:2558 : Successfully reloaded slash commands.
info - 26-12-2021 02:27:32:2732 : Logged in as Testing Robot. Ready on 4 servers, for a total of 2 users
debug - 26-12-2021 02:27:32:2732 : Refreshing slash commands...
debug - 26-12-2021 02:27:32:2732 : Refreshing slash commands...
debug - 26-12-2021 02:27:32:2732 : Successfully reloaded slash commands.
info - 26-12-2021 02:27:33:2733 : connected to the database successfully
debug - 26-12-2021 02:27:33:2733 : Successfully reloaded slash commands.
22 changes: 22 additions & 0 deletions logs/error.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
error - 26-12-2021 01:56:30:5630 : Invalid connection string "MANGO DB URL" MongoParseError: Invalid connection string "MANGO DB URL"
at new ConnectionString (C:\Users\Vishal\Desktop\Discord.js-v13-Handler With Mango Db\node_modules\mongodb-connection-string-url\lib\index.js:82:19)
at parseOptions (C:\Users\Vishal\Desktop\Discord.js-v13-Handler With Mango Db\node_modules\mongodb\lib\connection_string.js:213:17)
at new MongoClient (C:\Users\Vishal\Desktop\Discord.js-v13-Handler With Mango Db\node_modules\mongodb\lib\mongo_client.js:62:63)
at C:\Users\Vishal\Desktop\Discord.js-v13-Handler With Mango Db\node_modules\mongoose\lib\connection.js:779:16
at new Promise (<anonymous>)
at NativeConnection.Connection.openUri (C:\Users\Vishal\Desktop\Discord.js-v13-Handler With Mango Db\node_modules\mongoose\lib\connection.js:776:19)
at C:\Users\Vishal\Desktop\Discord.js-v13-Handler With Mango Db\node_modules\mongoose\lib\index.js:332:10
at C:\Users\Vishal\Desktop\Discord.js-v13-Handler With Mango Db\node_modules\mongoose\lib\helpers\promiseOrCallback.js:32:5
at new Promise (<anonymous>)
at promiseOrCallback (C:\Users\Vishal\Desktop\Discord.js-v13-Handler With Mango Db\node_modules\mongoose\lib\helpers\promiseOrCallback.js:31:10)
error - 26-12-2021 02:10:29:1029 : name is not defined ReferenceError: name is not defined
at Object.execute (C:\Users\Vishal\Desktop\Discord.js-v13-Handler With Mango Db\commands\uptime.js:15:16)
at module.exports (C:\Users\Vishal\Desktop\Discord.js-v13-Handler With Mango Db\events\guild\interactionCreate.js:7:15)
at Client.emit (node:events:390:28)
at InteractionCreateAction.handle (C:\Users\Vishal\Desktop\Discord.js-v13-Handler With Mango Db\node_modules\discord.js\src\client\actions\InteractionCreate.js:73:12)
at Object.module.exports [as INTERACTION_CREATE] (C:\Users\Vishal\Desktop\Discord.js-v13-Handler With Mango Db\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (C:\Users\Vishal\Desktop\Discord.js-v13-Handler With Mango Db\node_modules\discord.js\src\client\websocket\WebSocketManager.js:350:31)
at WebSocketShard.onPacket (C:\Users\Vishal\Desktop\Discord.js-v13-Handler With Mango Db\node_modules\discord.js\src\client\websocket\WebSocketShard.js:443:22)
at WebSocketShard.onMessage (C:\Users\Vishal\Desktop\Discord.js-v13-Handler With Mango Db\node_modules\discord.js\src\client\websocket\WebSocketShard.js:300:10)
at WebSocket.onMessage (C:\Users\Vishal\Desktop\Discord.js-v13-Handler With Mango Db\node_modules\ws\lib\event-target.js:199:18)
at WebSocket.emit (node:events:390:28)
Loading

0 comments on commit 4b306cc

Please sign in to comment.