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+ }
0 commit comments