From ba99719c2040e1f5b836987a7e1997f1617880c8 Mon Sep 17 00:00:00 2001 From: SileNce5k Date: Mon, 9 Jun 2025 20:38:34 +0200 Subject: [PATCH] Update setPresence custom variable logic --- util/setPresence.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/util/setPresence.js b/util/setPresence.js index 7f99e37..ea6f166 100644 --- a/util/setPresence.js +++ b/util/setPresence.js @@ -18,10 +18,22 @@ module.exports = function ({presenceText, presenceType, client}) { uptimeFormat = `less than a minute` } - let regex = [/\${guilds}/g,/\${prefix}/g,/\${uptime}/g, /\${members}/g]; - let replaceValue = [guildInfo.guildCount, globalPrefix, uptimeFormat, guildInfo.totalMembers]; - for(let i = 0; i < regex.length; i++){ - presenceText = presenceText.replace(regex[i], replaceValue[i]); + let presenceVariables = { + guilds: guildInfo.guildCount, + prefix: globalPrefix, + uptime: uptimeFormat, + members: guildInfo.totalMembers + } + + const regex = /(?<=\${)(.*?)(?=})/g; + const matches = presenceText.match(regex); + + if(matches){ + matches.forEach(match => { + if(presenceVariables[match]){ + presenceText = presenceText.replace(`\${${match}}`, presenceVariables[match]); + } + }); } try {