bdjs
Version:
A potent package for creating Discord bots.
42 lines (41 loc) • 1.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const Function_1 = require("../structures/Function");
const Properties_1 = tslib_1.__importDefault(require("../util/Properties"));
exports.default = new Function_1.BaseFunction({
description: 'Fetch a guild property.',
parameters: [
{
name: 'Property',
description: 'Guild property name.',
required: true,
resolver: 'String',
value: 'none'
},
{
name: 'Guild ID',
description: 'Guild ID to fetch the property from.',
required: false,
resolver: 'String',
value: 'd.ctx?.guild?.id'
}
],
code: async function (d, [property, guildID = d.ctx?.guild?.id]) {
if (property === undefined)
throw new d.error(d, 'required', 'Property Name', d.function?.name);
if (guildID === undefined)
throw new d.error(d, 'invalid', 'Guild ID', d.function?.name);
if (property.toLowerCase() === 'exists')
return d.bot?.guilds.cache.has(guildID);
const guild = await d.bot?.guilds.fetch(guildID);
if (!guild && property === 'exists')
return 'false';
else if (!guild && property !== 'exists')
throw new d.error(d, 'invalid', 'Property', d.function?.name);
const types = Object.keys(Properties_1.default.Guild);
if (!types.includes(property.toLowerCase()))
throw new d.error(d, 'invalid', 'Property', d.function?.name);
return Properties_1.default.Guild[property.toLowerCase()].code(guild);
}
});