Skip to content

Commit de21d6b

Browse files
committed
1.2.0
1 parent f6ec8e6 commit de21d6b

File tree

17 files changed

+397
-279
lines changed

17 files changed

+397
-279
lines changed

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,10 @@ dist
101101
.dynamodb/
102102

103103
# TernJS port file
104-
.tern-port
104+
.tern-port
105+
106+
107+
### ###
108+
### FOR THIS PROJECT ###
109+
### ###
110+
config.json

Data/config.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,29 @@ It is a simple event and command handler for Discord.js V13.
66
|-|-|-|
77
| 1.0.0 || [![Download](https://img.shields.io/badge/Download-v1.0.0-blue?style=flat-square)](https://github.com/MastiderMast/Discord.js-Advanced-Command-Handler/releases/tag/1.0.0) |
88
| 1.1.1 || [![Download](https://img.shields.io/badge/Download-v1.1.1-blue?style=flat-square)](https://github.com/MastiderMast/Discord.js-Advanced-Command-Handler/releases/tag/1.1.1) |
9-
| 1.2.0 || Work in progress |
9+
| 1.2.0 || [![Download](https://img.shields.io/badge/Download-v1.2.0-blue?style=flat-square)](https://github.com/MastiderMast/Discord.js-Advanced-Command-Handler/releases/tag/1.2.0) |
1010

11+
## Prerequisites
12+
1. MySQL database is required!
13+
2. Node.js 16.6.0 or newer is required.
14+
15+
## Installation
16+
1. run this SQL create code on your database:
17+
```
18+
CREATE TABLE `guilds` (
19+
`id` INT(10) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT,
20+
`guildid` VARCHAR(50) NULL DEFAULT '0' COLLATE 'utf8mb4_0900_ai_ci',
21+
`prefix` VARCHAR(50) NULL DEFAULT '!' COLLATE 'utf8mb4_0900_ai_ci',
22+
PRIMARY KEY (`id`) USING BTREE,
23+
UNIQUE INDEX `guildid` (`guildid`) USING BTREE
24+
)
25+
COLLATE='utf8mb4_0900_ai_ci'
26+
ENGINE=InnoDB
27+
;
28+
```
29+
2. Update your token and MySQL connection information in the config.
30+
3. Run the following command to install the package: `npm install`
31+
4. Rename teh `config.json.TEMPLATE` to `config.json`
32+
5. Run the bot with the following command: `npm start` or `node .`
33+
### Credits
1134
[I used his good code as a basis](https://github.com/Ferotiq/Discord.JS-13-Tutorial).

commands/hello.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

commands/helloworld.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const Command = require("../structures/command.js");
2+
const { red } = require('chalk');
3+
const embeds = require('../utils/embeds.js');
4+
5+
module.exports = new Command({
6+
name: "hello",
7+
description: "Hello world.",
8+
aliases: ["hey", "hi"],
9+
10+
async run(message, args, client) {
11+
try {
12+
13+
message.reply("Hello world!");
14+
15+
} catch (error) {
16+
embeds.errorEmbed(client, message, "Something went wrong.");
17+
console.log(red(`[COMMAND] In the command ${this.name} an error has occurred -> ${error}`))
18+
}
19+
}
20+
});

commands/setprefix.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
const Command = require("../structures/command.js");
2+
const Discord = require("discord.js");
3+
const config = require("../data/config.json");
4+
const { red } = require('chalk');
5+
const mysql = require('mysql');
6+
const util = require('util');
7+
8+
const embeds = require('../utils/embeds.js');
9+
10+
var con = mysql.createPool({
11+
multipleStatements: true,
12+
insecureAuth: true,
13+
host: `${config.mysql.host}`,
14+
port: `${config.mysql.port}`,
15+
user: `${config.mysql.user}`,
16+
password: `${config.mysql.password}`,
17+
database: `${config.mysql.database}`
18+
});
19+
20+
const dbquery = util.promisify(con.query).bind(con);
21+
22+
module.exports = new Command({
23+
name: "setprefix",
24+
description: "setprefix",
25+
aliases: [],
26+
27+
async run(message, args, client) {
28+
try {
29+
if (!message.member.permissions.has("MANAGE_ROLES")) return embeds.errorEmbed(client, message, "You do not have the permission to use this command!");
30+
31+
let rows = await dbquery(`SELECT * FROM guilds WHERE guildid = '${message.guild.id}'`);
32+
33+
if (!args[1]) return embeds.errorEmbed(client, message, `Use ${rows[0].prefix}setprefix <prefix>`);
34+
35+
await dbquery(`UPDATE guilds SET prefix = '${args[1]}' WHERE guildid = '${message.guild.id}'`);
36+
37+
const embed = new Discord.MessageEmbed()
38+
.setTitle("Prefix changed!")
39+
.setDescription(`The prefix has been changed to ${args[1]}`)
40+
.setColor("149C51")
41+
42+
message.reply({embeds: [embed]});
43+
44+
} catch (error) {
45+
embeds.errorEmbed(client, message, "Something went wrong.");
46+
console.log(red(`[COMMAND] In the command ${this.name} an error has occurred -> ${error}`))
47+
}
48+
}
49+
});

data/config.json.TEMPLATE

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"token": "TOKEN",
3+
"mysql": {
4+
"host": "HOST",
5+
"port": PORT,
6+
"user": "USER",
7+
"password": "PASSWORD",
8+
"database": "DATABASE"
9+
},
10+
"eval": "USERID"
11+
}

events/interactionCreate.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
const Command = require("../Structures/Command.js");
2-
const Event = require("../Structures/Event.js");
3-
const Discord = require("discord.js");
4-
const config = require("../Data/config.json");
5-
const { MessageSelectMenu, MessageActionRow, MessageButton } = require("discord.js");
6-
const { red, green, blue, yellow, cyan, greenBright, redBright, grey, yellowBright, cyanBright, black, blueBright } = require('chalk');
7-
const { version } = require('../package.json');
1+
const Event = require("../structures/event.js");
2+
const { red } = require('chalk');
83

9-
module.exports = new Event("interactionCreate", (client, interaction) => {
10-
try {
11-
//YOUR CODE
12-
} catch (error) {
13-
return console.log(red(`[EVENT] In the event interactionCreate an error has occurred -> ${error}`))
14-
}
4+
module.exports = new Event("interactionCreate", async(client, interaction) => {
5+
try {
6+
7+
} catch (error) {
8+
return console.log(red(`[EVENT] In the event interactionCreate an error has occurred -> ${error}`))
9+
}
1510
});

events/messageCreate.js

Lines changed: 54 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,54 @@
1-
const Command = require("../Structures/Command.js");
2-
const Event = require("../Structures/Event.js");
3-
const Discord = require("discord.js");
4-
const config = require("../Data/config.json");
5-
const { MessageSelectMenu, MessageActionRow, MessageButton } = require("discord.js");
6-
const { red, green, blue, yellow, cyan, greenBright, redBright, grey, yellowBright, cyanBright, black, blueBright } = require('chalk');
7-
const { version } = require('../package.json');
8-
9-
let prefix = config.prefix
10-
11-
module.exports = new Event("messageCreate", async (client, message) => {
12-
try {
13-
if (message.author.bot) return;
14-
15-
if (message.content.startsWith(prefix)) {
16-
17-
const args = message.content.substring(prefix.length).split(/ +/);
18-
const command = client.commands.find(cmd => cmd.name == args[0] || cmd.aliases.includes(args[0]));
19-
if (!command) return message.reply(`${args[0]} is not a valid command!`);
20-
command.run(message, args, client)
21-
}
22-
} catch (error) {
23-
return console.log(red(`[EVENT] In the event messageCreate an error has occurred -> ${error}`))
24-
}
25-
});
1+
const Event = require("../structures/event.js");
2+
const config = require("../data/config.json");
3+
const { red } = require('chalk');
4+
const mysql = require('mysql');
5+
const util = require('util');
6+
7+
const embeds = require('../utils/embeds.js');
8+
9+
var con = mysql.createPool({
10+
multipleStatements: true,
11+
insecureAuth: true,
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+
module.exports = new Event("messageCreate", async(client, message) => {
22+
try {
23+
if (message.author.bot) return;
24+
25+
const rows = await dbquery(`SELECT * FROM guilds WHERE guildid = ${message.guild.id}`);
26+
27+
if (rows.length < 1) await dbquery(`INSERT INTO guilds (id, guildid) VALUES (NULL, '${message.guild.id}')`);
28+
29+
const p = await getprefix(message.guild.id);
30+
const prefix = await p
31+
32+
if (message.content.startsWith(prefix)) {
33+
const args = message.content.substring(prefix.length).split(/ +/);
34+
const command = client.commands.find(cmd => cmd.name == args[0] || cmd.aliases.includes(args[0]));
35+
if (!command) return //message.reply(`${args[0]} is not a valid command!`);
36+
command.run(message, args, client)
37+
} else {
38+
// Here you can add commands that are not have a prefix.
39+
// like when somebody pings the bot.
40+
}
41+
42+
} catch (error) {
43+
embeds.errorEmbed(client, message, "Something went wrong.");
44+
return console.log(red(`[EVENT] In the event messageCreate an error has occurred -> ${error}`))
45+
}
46+
});
47+
48+
async function getprefix(id) {
49+
const rows = await dbquery(`SELECT * FROM guilds WHERE guildid = '${id}'`);
50+
if (rows.length < 1) {
51+
return "%";
52+
}
53+
return rows[0].prefix;
54+
}

events/ready.js

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
1-
const Command = require("../Structures/Command.js");
2-
const Event = require("../Structures/Event.js");
3-
const Discord = require("discord.js");
4-
const config = require("../Data/config.json");
5-
const { MessageSelectMenu, MessageActionRow, MessageButton } = require("discord.js");
6-
const { red, green, blue, yellow, cyan, greenBright, redBright, grey, yellowBright, cyanBright, black, blueBright } = require('chalk');
1+
const Event = require("../structures/event.js");
2+
const config = require("../data/config.json");
3+
const { red, yellow } = require('chalk');
74
const { version } = require('../package.json');
5+
const mysql = require('mysql');
6+
const util = require('util');
87

9-
module.exports = new Event("ready", client => {
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("ready", async(client) => {
1021
try {
1122
console.log(yellow(`[LOGIN] logged in as ${client.user.tag} -> Version ${version}`))
12-
23+
1324
//ACTIVITY
1425
let status_state = 0;
15-
client.user.setActivity('you', { type: 'WATCHING' });
1626
setInterval(() => {
1727
let status_presences = [
18-
{ type: 'PLAYING', message: 'Version: '+ version},
19-
{ type: 'WATCHING', message: `${client.guilds.cache.size} server.`},
20-
{ type: 'WATCHING', message: `${client.users.cache.size} user.`},
21-
{ type: 'WATCHING', message: `${client.commands.size} commands.`}
28+
{ type: 'PLAYING', message: 'Version: ' + version },
29+
{ type: 'LISTENING', message: '@' + client.user.tag },
2230
];
2331
status_state = (status_state + 1) % status_presences.length;
2432
status_presence = status_presences[status_state];
@@ -28,4 +36,4 @@ module.exports = new Event("ready", client => {
2836
} catch (error) {
2937
return console.log(red(`[EVENT] In the event ready an error has occurred -> ${error}`))
3038
}
31-
});
39+
});

0 commit comments

Comments
 (0)