Skip to content

Commit 2ce4b5d

Browse files
committed
v1.3.1
1 parent 6c5ccbe commit 2ce4b5d

File tree

6 files changed

+84
-34
lines changed

6 files changed

+84
-34
lines changed

README.md

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,14 @@
22

33
It is a simple event and command handler for Discord.js V14.
44

5-
[![Download](https://img.shields.io/badge/Download-v1.3.0-blue?style=flat-square)](https://github.com/MastiderMast/Discord.js-Advanced-Command-Handler/releases/tag/1.3.0)
5+
[![Download](https://img.shields.io/badge/Download-blue?style=flat-square)](https://github.com/MastiderMast/Discord.js-Advanced-Command-Handler/releases)
66

77
## Prerequisites
88
1. MySQL database is required!
99
2. Node.js v18.7.0 or newer is required.
1010

1111
## Installation
12-
1. run this SQL create code on your database:
13-
```
14-
CREATE TABLE `guilds` (
15-
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
16-
`guildid` VARCHAR(50) NULL DEFAULT '0' COLLATE 'utf8mb4_0900_ai_ci',
17-
`prefix` VARCHAR(50) NULL DEFAULT '!' COLLATE 'utf8mb4_0900_ai_ci',
18-
PRIMARY KEY (`id`) USING BTREE,
19-
UNIQUE INDEX `guildid` (`guildid`) USING BTREE
20-
)
21-
COLLATE='utf8mb4_0900_ai_ci'
22-
ENGINE=InnoDB
23-
;
24-
```
25-
2. Update your token and MySQL connection information in the config.
26-
3. Run the following command to install the package: `npm install`
27-
4. Rename the `config.json.TEMPLATE` to `config.json`
28-
5. Run the bot with the following command: `npm start` or `node .`
12+
1. Update your token and MySQL connection information in the config.
13+
2. Run the following command to install the package: `npm install`
14+
3. Rename the `config.json.TEMPLATE` to `config.json`
15+
4. Run the bot with the following command: `node .`

commands/setprefix.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const Command = require("../structures/command.js");
22
const Discord = require("discord.js");
33
const config = require("../data/config.json");
4-
const { red } = require('chalk');
54
const mysql = require('mysql2');
65
const util = require('util');
76

events/guildCreate.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const Event = require("../structures/event.js");
2+
const config = require("../data/config.json");
3+
const { red, yellow } = require('chalk');
4+
const { version } = require('../package.json');
5+
const mysql = require('mysql2');
6+
const util = require('util');
7+
8+
var con = mysql.createPool({
9+
multipleStatements: true,
10+
insecureAuth: true,
11+
host: `${config.mysql.host}`,
12+
port: `${config.mysql.port}`,
13+
user: `${config.mysql.user}`,
14+
password: `${config.mysql.password}`,
15+
database: `${config.mysql.database}`
16+
});
17+
18+
const dbquery = util.promisify(con.query).bind(con);
19+
20+
module.exports = new Event("guildCreate", async(client) => {
21+
try {
22+
console.log(yellow(`[LOGIN] logged in as ${client.user.tag} -> Version ${version}`))
23+
24+
//ACTIVITY
25+
let status_state = 0;
26+
setInterval(() => {
27+
let status_presences = [
28+
{ type: 'PLAYING', message: 'Version: ' + version },
29+
{ type: 'LISTENING', message: '@' + client.user.tag },
30+
];
31+
status_state = (status_state + 1) % status_presences.length;
32+
status_presence = status_presences[status_state];
33+
client.user.setActivity(status_presence.message, { type: status_presence.type });
34+
}, 5000);
35+
36+
} catch (error) {
37+
return console.log(red(`[EVENT] In the event ready an error has occurred -> ${error}`))
38+
}
39+
});

events/messageCreate.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,12 @@ module.exports = new Event("messageCreate", async(client, message) => {
1717
try {
1818
if (message.author.bot) return;
1919

20-
const rows = await dbquery(`SELECT * FROM guilds WHERE guildid = ${message.guild.id}`);
21-
22-
if (rows.length < 1) await dbquery(`INSERT INTO guilds (id, guildid) VALUES (NULL, '${message.guild.id}')`);
23-
24-
const p = await getprefix(message.guild.id);
25-
const prefix = await p;
20+
let prefix = await getprefix(message.guild.id);
2621

2722
if (message.content.startsWith(prefix)) {
2823
const args = message.content.substring(prefix.length).split(/ +/);
2924
const command = client.commands.find(cmd => cmd.name == args[0] || cmd.aliases.includes(args[0]));
30-
if (!command) return //message.reply(`${args[0]} is not a valid command!`); //uncomment this if you want that the bot replies when the error is not a valid command!
25+
if (!command) return //message.reply(`${args[0]} is not a valid command!`); //uncomment if you want that the bot replies when the command is not a valid command!
3126
command.run(message, args, client)
3227
} else {
3328
// Here you can add commands that are not have a prefix.
@@ -39,10 +34,15 @@ module.exports = new Event("messageCreate", async(client, message) => {
3934
}
4035
});
4136

42-
async function getprefix(id) {
43-
const rows = await dbquery(`SELECT * FROM guilds WHERE guildid = '${id}'`);
37+
async function getprefix(guildid) {
38+
let rows = await dbquery(`SELECT prefix FROM guilds WHERE guildid = ${guildid}`);
4439
if (rows.length < 1) {
45-
return "%";
40+
await dbquery(`INSERT IGNORE INTO guilds (id, guildid) VALUES (NULL, '${guildid}')`);
41+
return "!";
42+
}
43+
if (rows[0].prefix == null) {
44+
await dbquery(`UPDATE guilds SET prefix = '!' WHERE guildid = ${guildid}`);
45+
return "!";
4646
}
4747
return rows[0].prefix;
4848
}

index.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,34 @@ console.clear();
33
const Client = require("./structures/client.js");
44
const client = new Client();
55
const config = require("./data/config.json");
6+
const { yellow } = require('chalk');
7+
8+
const mysql = require('mysql2');
9+
const util = require('util');
10+
11+
var con = mysql.createPool({
12+
host: `${config.mysql.host}`,
13+
port: `${config.mysql.port}`,
14+
user: `${config.mysql.user}`,
15+
password: `${config.mysql.password}`,
16+
database: `${config.mysql.database}`
17+
});
18+
19+
const dbquery = util.promisify(con.query).bind(con);
20+
21+
// Check if Table Exists if not the bot will create it
22+
dbquery(`SHOW TABLES LIKE 'guilds'`).then(async (rows) => {
23+
if (rows.length < 1) {
24+
dbquery(`CREATE TABLE guilds (
25+
id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
26+
guildid VARCHAR(50) NULL DEFAULT '0' COLLATE 'utf8mb4_0900_ai_ci',
27+
prefix VARCHAR(50) NULL DEFAULT '!' COLLATE 'utf8mb4_0900_ai_ci',
28+
PRIMARY KEY (id) USING BTREE,
29+
UNIQUE INDEX guildid (guildid) USING BTREE
30+
);`)
31+
console.log(yellow(`[MySQL] Created table guilds`));
32+
}
33+
})
634

735
process.on('uncaughtException', function (err) {
836
console.error(err);

package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
{
22
"name": "discord.js-advanced-command-handler",
3-
"version": "1.3.0",
3+
"version": "1.3.1",
44
"main": "index.js",
5-
"scripts": {
6-
"test": "echo \"Error: no test specified\" && exit 1"
7-
},
85
"repository": {
96
"type": "git",
107
"url": "git+https://github.com/MastiderMast/Discord.js-Advanced-Command-Handler.git"
@@ -21,5 +18,5 @@
2118
"fs": "^0.0.1-security",
2219
"mysql2": "^2.3.3"
2320
},
24-
"description": ""
21+
"description": "Simple Discord.js V14 Command and Event Handler"
2522
}

0 commit comments

Comments
 (0)