diff --git a/events/messageCreate.js b/events/messageCreate.js index 79bb05e..3112ee7 100644 --- a/events/messageCreate.js +++ b/events/messageCreate.js @@ -6,65 +6,74 @@ const config = require("../settings/config"); client.on("messageCreate", async (message) => { if (message.author.bot || !message.guild || !message.id) return; let Xprefix = PREFIX; - var XversEmention = `<@${client.user.id}>`; - const args = message.content.slice(Xprefix.length).trim().split(/ +/); + let MentionPrefix = new RegExp( + `^(<@!?${client.user.id}>|${escapeRegex(Xprefix)})\\s*` + ); + if (!MentionPrefix.test(message.content)) return; + const [, nprefix] = message.content.match(MentionPrefix); + const args = message.content.slice(nprefix.length).trim().split(/ +/); const cmd = args.shift().toLowerCase(); - if (message.content ===XversEmention) { - let Github = new MessageActionRow().addComponents([ - new MessageButton() + if (cmd.length === 0) { + if (nprefix.includes(client.user.id)) { + + let Github = new MessageActionRow().addComponents([ + new MessageButton() .setLabel("XversE-Adv-Handler (Github)") .setEmoji(config.Emoji.github) .setStyle("LINK") .setURL(config.XversE.XversE), - ]); + ]); - let row = new MessageActionRow().addComponents([ - new MessageButton() - .setLabel("Invite me") - .setEmoji(config.Emoji.inv) - .setStyle("LINK") - .setURL(config.XversE.inviteURL.replace("XversE", client.user.id)), + let row = new MessageActionRow().addComponents([ + new MessageButton() + .setLabel("Invite me") + .setEmoji(config.Emoji.inv) + .setStyle("LINK") + .setURL(config.XversE.inviteURL.replace("XversE", client.user.id)), - new MessageButton() - .setLabel("Support") - .setEmoji(config.Emoji.support) - .setStyle("LINK") - .setURL(config.XversE.DiscordServer), + new MessageButton() + .setLabel("Support") + .setEmoji(config.Emoji.support) + .setStyle("LINK") + .setURL(config.XversE.DiscordServer), - new MessageButton() - .setLabel("Jarvis") - .setEmoji(config.Emoji.crown) - .setStyle("LINK") - .setURL(config.XversE.Jarvis), - ]); + new MessageButton() + .setLabel("Jarvis") + .setEmoji(config.Emoji.crown) + .setStyle("LINK") + .setURL(config.XversE.Jarvis), + ]); - message.reply({ - embeds: [ - new MessageEmbed() - .setColor(config.Embed.color) - .setAuthor({ - name: `${client.user.username} | Introduction`, - iconURL: client.user.displayAvatarURL({ dynamic: true }), - }) - .setDescription( - `${config.Emoji.hey} Hey ${message.author} I am ${client.user} a Advanced Discord XversE Command Handler Bot... ${config.Emoji.hey}\n\n${config.Emoji.dot} Prefix for in this Server is : **\`${Xprefix}\`**\n${config.Emoji.dot} Need help ? Regarding commands, Type \`/help\` or \`${Xprefix}help\``, - ) - .setImage(config.Images.Banner) - .setFooter({ - text: config.Embed.footer, - iconURL: `${client.user.displayAvatarURL({ dynamic: true })}`, - }), - ], - components: [row, Github], - }); + message.reply({ + embeds: [ + new MessageEmbed() + .setColor(config.Embed.color) + .setAuthor({ + name: `${client.user.username} | Introduction`, + iconURL: client.user.displayAvatarURL({ dynamic: true }), + }) + .setDescription(`${config.Emoji.hey} Hey ${message.author} I am ${client.user} a Advanced Discord XversE Command Handler Bot... ${config.Emoji.hey}\n\n${config.Emoji.dot} Prefix for in this Server is : **\`${Xprefix}\`**\n${config.Emoji.dot} Need help ? Regarding commands, Type \`/help\` or \`${Xprefix}help\``) + .setImage(config.Images.Banner) + .setFooter({ + text: config.Embed.footer, + iconURL: `${client.user.displayAvatarURL({ dynamic: true })}`, + }), + ], + components: [row, Github], + }) + } } const command = client.commands.get(cmd) || client.commands.find((cmds) => cmds.aliases && cmds.aliases.includes(cmd)); if (!command) return; if (command) { - command.Xexecute(client, message, args); + command.Xexecute(client, message, args, nprefix); } -}); \ No newline at end of file +}); + +function escapeRegex(newprefix) { + return newprefix.replace(/[.*+?^${}()|[\]\\]/g, `\\$&`); +}