@@ -2,7 +2,7 @@ const fs = require('fs');
22const Discord = require ( 'discord.js' ) ;
33const { connect } = require ( 'mongoose' ) ;
44//Get the prefix and token from the conf.json
5- const { token } = require ( './conf.json' ) ;
5+ const { token, databaseURL } = require ( './conf.json' ) ;
66//Get the GuildModel from the models directory
77const GuildModel = require ( './models/Guild' ) ;
88//Register the client and include partials for reactions
@@ -23,19 +23,6 @@ let prefix;
2323client . once ( 'ready' , ( ) => {
2424 //Log to console that the bot is ready
2525 console . log ( `${ client . user . username } is now ready!` ) ;
26- //Fetch information from the database upon startup
27- ( async ( ) => {
28- try {
29- //Fetch the Model for each guild the bot is in
30- const req = await GuildModel . find ( { id : guild } ) ;
31- //Request the information
32- id = req . id ;
33- prefix = req . prefix ;
34- console . log ( `Startup Information Fetched` )
35- } catch ( e ) {
36- console . log ( e . stack )
37- }
38- } ) ( ) ;
3926} ) ;
4027//Guild Create Event (When the bot joins a guild it logs the guild into the database)
4128client . on ( 'guildCreate' , async guild => {
@@ -51,44 +38,39 @@ client.on('guildCreate', async guild => {
5138} ) ;
5239//Message Listener
5340client . on ( 'message' , message => {
54- /*
55- if (message.content === "!sync" || !message.author.bot) {
5641 ( async ( ) => {
5742 try {
5843 const req = await GuildModel . findOne ( { id : message . guild . id } ) ;
59- id = req.id;
6044 prefix = req . prefix ;
61- console.log(`${message.guild.id} database/information in use is now in sync`)
6245 } catch ( e ) {
6346 console . log ( e . stack )
6447 }
65- })();
66- }
67- */
68- //If a message does not start with the prefix don't run it as a command
69- if ( ! message . content . startsWith ( prefix ) || message . author . bot ) return ;
70- //Set the command prefix
71- const args = message . content . slice ( prefix . length ) . split ( / + / ) ;
72- const commandName = args . shift ( ) . toLowerCase ( ) ;
48+ } ) ( ) . then ( ( ) => {
49+ //If a message does not start with the prefix don't run it as a command
50+ if ( ! message . content . startsWith ( prefix ) || message . author . bot ) return ;
51+ //Set the command prefix
52+ const args = message . content . slice ( prefix . length ) . split ( / + / ) ;
53+ const commandName = args . shift ( ) . toLowerCase ( ) ;
7354
74- //Gets the commands by the name within the commands file
75- const command = client . commands . get ( commandName )
76- || client . commands . find ( cmd => cmd . aliases && cmd . aliases . includes ( commandName ) ) ;
77- //If it has the prefix but is not a command, return it and not run a command
78- if ( ! command ) return ;
55+ //Gets the commands by the name within the commands file
56+ const command = client . commands . get ( commandName )
57+ || client . commands . find ( cmd => cmd . aliases && cmd . aliases . includes ( commandName ) ) ;
58+ //If it has the prefix but is not a command, return it and not run a command
59+ if ( ! command ) return ;
7960
80- //Try to execute the command, if it doesn't work send the error message
81- try {
82- command . execute ( message , args ) ;
83- console . log ( `${ message . author . username } ran the command ${ prefix } ${ commandName } ` )
84- } catch ( error ) {
85- //Tell the user who executed the command that there was an error
86- message . reply ( 'There was an error trying to execute that command! Please contact the bot developer.' ) ;
87- //state which command caused the error and in what guild it originated from
88- console . log ( `${ prefix } ${ commandName } had an error in (${ message . guild . id } )` ) ;
89- //Log the command error
90- console . error ( error ) ;
91- }
61+ //Try to execute the command, if it doesn't work send the error message
62+ try {
63+ command . execute ( message , args ) ;
64+ console . log ( `${ message . guild . name } - ${ message . author . username } ran ${ commandName } ` )
65+ } catch ( error ) {
66+ //Tell the user who executed the command that there was an error
67+ message . reply ( 'There was an error trying to execute that command! Please contact the bot developer.' ) ;
68+ //state which command caused the error and in what guild it originated from
69+ console . log ( `${ message . guild . name } - ${ commandName } had an error!` ) ;
70+ //Log the command error
71+ console . error ( error ) ;
72+ }
73+ } )
9274} ) ;
9375
9476//Message Reaction Add Event (When a user adds a reaction to a message)
@@ -106,7 +88,7 @@ client.on(`guildMemberRemove`, async member => {
10688//Connections + Logins
10789( async ( ) => {
10890 //Connect to the MongoDB
109- await connect ( 'Database URL' , {
91+ await connect ( databaseURL , {
11092 useNewUrlParser : true ,
11193 useFindAndModify : false ,
11294 useUnifiedTopology : true
0 commit comments