Skip to content

Commit 9559030

Browse files
authored
Merge pull request #66 from SimonB50/patch-1
NEW | findGuild() Util
2 parents 78a5e2a + ca5f5a7 commit 9559030

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Modules/Utils.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,25 @@ module.exports = {
250250

251251
return returnObject;
252252
},
253+
/**
254+
* @param {String} name
255+
* @param {Discord.Client} client
256+
* @param {Boolean} notify
257+
* @returns {Discord.Guild | void}
258+
*/
259+
findGuild: (name, client, notify = true) => {
260+
if (!name) return module.exports.logError(`[Utils] [findGuild] Invalid input for guild name.`);
261+
if (!client) return module.exports.logError(`[Utils] [findGuild] Invalid input for client.`);
262+
if (typeof name == "bigint" || typeof name == "number") name = name.toString();
263+
264+
let returnObject = false;
265+
const guild = client.guilds.cache.find((g) => g.name.toLowerCase() === name.toLowerCase() || g.id === name);
266+
267+
if (guild) returnObject = guild;
268+
else if (notify) module.exports.logError(`[Utils] [findGuild] ${chalk.bold(name)} guild was not found.`);
269+
270+
return returnObject;
271+
},
253272
/**
254273
* @param {Discord.GuildMember} member
255274
* @param {String | Array} name

0 commit comments

Comments
 (0)