Skip to content

Commit

Permalink
[New] Bot now checks if there is a custom prefix for the guild in the…
Browse files Browse the repository at this point in the history
… database
  • Loading branch information
naseif committed Oct 4, 2021
1 parent d2540df commit 6e062ac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 10 additions & 3 deletions events/messageCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@ const { prefix } = require("../config.json");
module.exports = {
name: "messageCreate",
async run(message, client) {
if (message.author.bot) return;
if (!message.guild) return;

const args = message.content.slice(prefix.length).trim().split(/ +/);
let defaultPrefix;
let mongoPrefix = await client.db.get(`guild_prefix_${message.guildId}`);

mongoPrefix ? (defaultPrefix = mongoPrefix) : (defaultPrefix = prefix);

if (!message.content.startsWith(defaultPrefix) || message.author.bot)
return;

const args = message.content.slice(defaultPrefix.length).trim().split(/ +/);
const commandName = args.shift().toLowerCase();

const command =
Expand All @@ -18,7 +25,7 @@ module.exports = {
if (!command) return;

try {
command.run(message, args, client, prefix);
command.run(message, args, client, defaultPrefix);
} catch (error) {
client.logger(error.message, "error");
}
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ const player = new Player(client);
client.player = player;
client.commands = new Collection();
client.logger = logger;
// client.db = new Database(mongourl);
client.db = new Database(mongourl);

// Register everything...
commandsHelper.registerAllCommands(__dirname + "/commands", client);
commandsHelper.registerAllEvents(__dirname + "/events", client);
playerEvents(client.player);

// Connect to DATABASE
// connectDatabase(mongourl, client);
connectDatabase(mongourl, client);
// ... and go!
client.login(token);

0 comments on commit 6e062ac

Please sign in to comment.