oceanic.js
Version:
A NodeJS library for interfacing with Discord.
1,142 lines (1,141 loc) • 112 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
/** @module Guild */
const Role_1 = tslib_1.__importDefault(require("./Role"));
const Base_1 = tslib_1.__importDefault(require("./Base"));
const GuildChannel_1 = tslib_1.__importDefault(require("./GuildChannel"));
const Member_1 = tslib_1.__importDefault(require("./Member"));
const GuildScheduledEvent_1 = tslib_1.__importDefault(require("./GuildScheduledEvent"));
const ThreadChannel_1 = tslib_1.__importDefault(require("./ThreadChannel"));
const Integration_1 = tslib_1.__importDefault(require("./Integration"));
const AutoModerationRule_1 = tslib_1.__importDefault(require("./AutoModerationRule"));
const Permission_1 = tslib_1.__importDefault(require("./Permission"));
const VoiceState_1 = tslib_1.__importDefault(require("./VoiceState"));
const StageInstance_1 = tslib_1.__importDefault(require("./StageInstance"));
const Channel_1 = tslib_1.__importDefault(require("./Channel"));
const Invite_1 = tslib_1.__importDefault(require("./Invite"));
const AuditLogEntry_1 = tslib_1.__importDefault(require("./AuditLogEntry"));
const Soundboard_1 = tslib_1.__importDefault(require("./Soundboard"));
const Constants_1 = require("../Constants");
const Routes = tslib_1.__importStar(require("../util/Routes"));
const TypedCollection_1 = tslib_1.__importDefault(require("../util/TypedCollection"));
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore-line
const Errors_1 = require("../util/Errors");
const SimpleCollection_1 = tslib_1.__importDefault(require("../util/SimpleCollection"));
/** Represents a Discord server. */
class Guild extends Base_1.default {
_clientMember;
// if the guild was retrieved from rest
_rest;
_shard;
/** This guild's afk voice channel. */
afkChannel;
/** The ID of this guild's afk voice channel. */
afkChannelID;
/** The seconds after which voice users will be moved to the afk channel. */
afkTimeout;
/** The application that created this guild, if applicable. */
application;
/** The ID of the application that created this guild, if applicable. */
applicationID;
/** The approximate number of members in this guild (if retrieved with counts). */
approximateMemberCount;
/** The approximate number of non-offline members in this guild (if retrieved with counts). */
approximatePresenceCount;
/** The cached audit log entries. This requires both the {@link Constants~Intents.GUILD_MODERATION | GUILD_MODERATION} intent, as well as the {@link Constants~Permissions | VIEW_AUDIT_LOG } permission. */
auditLogEntries;
/** The auto moderation rules in this guild. */
autoModerationRules;
/** The hash of this guild's banner. */
banner;
/** The channels in this guild. */
channels;
/** The default [message notifications level](https://discord.com/developers/docs/resources/guild#guild-object-default-message-notification-level) of this guild. */
defaultMessageNotifications;
/** The description of this guild. */
description;
/** The discovery splash of this guild. Only present if the guild has the `DISCOVERABLE` feature. */
discoverySplash;
/** The custom emojis of this guild. */
emojis;
/** The [explicit content filter](https://discord.com/developers/docs/resources/guild#guild-object-explicit-content-filter-level) of this guild. */
explicitContentFilter;
/** The [features](https://discord.com/developers/docs/resources/guild#guild-object-guild-features) this guild has. */
features;
/** The icon hash of this guild. */
icon;
incidentActions;
/** The integrations in this guild. */
integrations;
/** The guild's inventory settings. */
inventorySettings;
/** The cached invites in this guild. This will only be populated by invites created while the client is active. */
invites;
/** The date at which this guild was joined. */
joinedAt;
/** If this guild is considered large. */
large;
latestOnboardingQuestionID;
/** The maximum amount of members this guild can have. */
maxMembers;
/** The maximum amount of people that can be present at a time in this guild. Only present for very large guilds. */
maxPresences;
/** The maximum amount of users that can be present in a stage video channel. */
maxStageVideoChannelUsers;
/** The maximum amount of users that can be present in a video channel. */
maxVideoChannelUsers;
/** The number of members in this guild. */
memberCount;
/** The cached members in this guild. */
members;
/** The required [mfa level](https://discord.com/developers/docs/resources/guild#guild-object-mfa-level) for moderators of this guild. */
mfaLevel;
/** The name of this guild. */
name;
/** The [nsfw level](https://discord.com/developers/docs/resources/guild#guild-object-guild-nsfw-level) of this guild. */
nsfwLevel;
/** The owner of this guild. */
owner;
/** The ID of the owner of this guild. */
ownerID;
/** The [preferred locale](https://discord.com/developers/docs/reference#locales) of this guild. */
preferredLocale;
/** If this guild has the boost progress bar enabled. */
premiumProgressBarEnabled;
/** The number of nitro boosts this guild has. */
premiumSubscriptionCount;
/** The [boost level](https://discord.com/developers/docs/resources/guild#guild-object-premium-tier) of this guild. */
premiumTier;
/** The channel where notices from Discord are received. Only present in guilds with the `COMMUNITY` feature. */
publicUpdatesChannel;
/** The id of the channel where notices from Discord are received. Only present in guilds with the `COMMUNITY` feature. */
publicUpdatesChannelID;
/** @deprecated The region of this guild. */
region;
/** The roles in this guild. */
roles;
/** The channel where rules/guidelines are displayed. Only present in guilds with the `COMMUNITY` feature. */
rulesChannel;
/** The id of the channel where rules/guidelines are displayed. Only present in guilds with the `COMMUNITY` feature. */
rulesChannelID;
/** The channel where safety related notices are posted. */
safetyAlertsChannel;
/** The ID if the channel where safety related notices are posted. */
safetyAlertsChannelID;
/** The scheduled events in this guild. */
scheduledEvents;
/** The soundboard sounds in this guild. */
soundboardSounds;
/** The invite splash hash of this guild. */
splash;
/** The stage instances in this guild. */
stageInstances;
/** The custom stickers of this guild. */
stickers;
/** The channel where welcome messages and boosts notices are posted. */
systemChannel;
/** The [flags](https://discord.com/developers/docs/resources/guild#guild-object-system-channel-flags) for the system channel. */
systemChannelFlags;
/** The ID of the channel where welcome messages and boosts notices are posted. */
systemChannelID;
/** The threads in this guild. */
threads;
/** If this guild is unavailable. */
unavailable;
/** The vanity url of this guild. Only present in guilds with the `VANITY_URL` feature. */
vanityURLCode;
/** The [verification level](https://discord.com/developers/docs/resources/guild#guild-object-verification-level) of this guild. */
verificationLevel;
/** The voice states of members in voice channels. */
voiceStates;
/** The welcome screen configuration. Only present in guilds with the `WELCOME_SCREEN_ENABLED` feature. */
welcomeScreen;
/** The channel the widget will generate an invite to, or `null` if set to no invite. */
widgetChannel;
/** The id of the channel the widget will generate an invite to, or `null` if set to no invite. */
widgetChannelID;
/** If the widget is enabled. */
widgetEnabled;
constructor(data, client, rest) {
super(data.id, client);
this.afkChannelID = null;
this.afkTimeout = 0;
this.applicationID = data.application_id;
this.auditLogEntries = new TypedCollection_1.default(AuditLogEntry_1.default, client, client.util._getLimit("auditLogEntries", this.id));
this.autoModerationRules = new TypedCollection_1.default(AutoModerationRule_1.default, client, client.util._getLimit("autoModerationRules", this.id));
this.banner = null;
this.channels = new TypedCollection_1.default(GuildChannel_1.default, client, client.util._getLimit("channels", this.id), {
construct: (channel) => {
client.channelGuildMap.set(channel.id, this.id);
return Channel_1.default.from(channel, client);
},
delete: (id) => {
client.channelGuildMap.delete(id);
}
});
this.defaultMessageNotifications = data.default_message_notifications;
this.description = null;
this.discoverySplash = null;
this.emojis = new SimpleCollection_1.default(rawEmoji => this.client.util.convertGuildEmoji(rawEmoji), client.util._getLimit("emojis", this.id), "merge");
this.explicitContentFilter = data.explicit_content_filter;
this.features = [];
this.icon = null;
this.incidentActions = null;
this.integrations = new TypedCollection_1.default(Integration_1.default, client, client.util._getLimit("integrations", this.id));
this.inventorySettings = null;
this.invites = new SimpleCollection_1.default(rawInvite => new Invite_1.default(rawInvite, client), client.util._getLimit("invites", this.id), "update", "code");
this.joinedAt = null;
this.large = (data.member_count ?? data.approximate_member_count ?? 0) >= client.shards.options.largeThreshold;
this.latestOnboardingQuestionID = null;
this.memberCount = data.member_count ?? data.approximate_member_count ?? 0;
this.members = new TypedCollection_1.default(Member_1.default, client, client.util._getLimit("members", this.id));
this.mfaLevel = data.mfa_level;
this.name = data.name;
this.nsfwLevel = data.nsfw_level;
this.owner = data.owner_id === null ? null : client.users.get(data.owner_id);
this.ownerID = data.owner_id;
this.preferredLocale = data.preferred_locale;
this.premiumProgressBarEnabled = data.premium_progress_bar_enabled;
this.premiumTier = data.premium_tier;
this.publicUpdatesChannelID = null;
this.roles = new TypedCollection_1.default(Role_1.default, client, client.util._getLimit("roles", this.id));
this.rulesChannelID = null;
this.safetyAlertsChannelID = null;
this.scheduledEvents = new TypedCollection_1.default(GuildScheduledEvent_1.default, client, client.util._getLimit("scheduledEvents", this.id));
this.soundboardSounds = new TypedCollection_1.default(Soundboard_1.default, client, client.util._getLimit("soundboardSounds", this.id));
this.splash = null;
this.stageInstances = new TypedCollection_1.default(StageInstance_1.default, client, client.util._getLimit("stageInstances", this.id));
this.stickers = new SimpleCollection_1.default(rawSticker => client.util.convertSticker(rawSticker), client.util._getLimit("stickers", this.id), "merge");
this.systemChannelID = null;
this.systemChannelFlags = data.system_channel_flags;
this.threads = new TypedCollection_1.default(ThreadChannel_1.default, client, client.util._getLimit("guildThreads", this.id), {
construct: (thread) => {
client.threadGuildMap.set(thread.id, this.id);
return Channel_1.default.from(thread, client);
},
delete: (id) => {
client.threadGuildMap.delete(id);
}
});
this.unavailable = !!data.unavailable;
this.vanityURLCode = data.vanity_url_code;
this.verificationLevel = data.verification_level;
this.voiceStates = new TypedCollection_1.default(VoiceState_1.default, client, client.util._getLimit("voiceStates", this.id));
this.widgetChannelID = data.widget_channel_id === null ? null : data.widget_channel_id;
for (const role of data.roles) {
this.roles.update(role, data.id);
}
this.update(data);
this._rest = !!rest;
if (data.channels) {
for (const channelData of data.channels) {
channelData.guild_id = this.id;
client.channelGuildMap.set(channelData.id, this.id); // @TODO this seems redundant
this.channels.update(channelData);
}
}
if (data.threads) {
for (const threadData of data.threads) {
threadData.guild_id = this.id;
this.threads.update(threadData);
}
}
if (data.members) {
for (const rawMember of data.members) {
const member = this.members.update({ ...rawMember, id: rawMember.user?.id }, this.id);
if (this.client["_user"] && member.id === this.client.user.id) {
this._clientMember = member;
}
}
}
if (data.stage_instances) {
for (const stageInstance of data.stage_instances) {
stageInstance.guild_id = this.id;
this.stageInstances.update(stageInstance);
}
}
if (data.presences) {
for (const presence of data.presences) {
const member = this.members.get(presence.user.id);
if (member) {
delete presence.user;
member.presence = {
clientStatus: presence.client_status,
guildID: presence.guild_id,
status: presence.status,
activities: presence.activities?.map(activity => ({
createdAt: activity.created_at,
name: activity.name,
type: activity.type,
applicationID: activity.application_id,
assets: activity.assets ? {
largeImage: activity.assets.large_image,
largeText: activity.assets.large_text,
smallImage: activity.assets.small_image,
smallText: activity.assets.small_text
} : undefined,
buttons: activity.buttons,
details: activity.details,
emoji: activity.emoji,
flags: activity.flags,
instance: activity.instance,
party: activity.party,
secrets: activity.secrets,
state: activity.state,
timestamps: activity.timestamps,
url: activity.url
}))
};
}
else {
client.emit("debug", `Rogue presence (user: ${presence.user.id}, guild: ${this.id})`);
}
}
}
if (data.voice_states) {
for (const voiceState of data.voice_states) {
if (!this.members.has(voiceState.user_id) || !voiceState.channel_id) {
continue;
}
voiceState.guild_id = this.id;
this.voiceStates.update({ ...voiceState, id: voiceState.user_id });
const channel = this.channels.get(voiceState.channel_id);
const member = this.members.update({ id: voiceState.user_id, deaf: voiceState.deaf, mute: voiceState.mute }, this.id);
if (this._clientMember) {
this._clientMember["update"]({ deaf: voiceState.deaf, mute: voiceState.mute });
}
if (channel && "voiceMembers" in channel) {
channel.voiceMembers.add(member);
}
if (client.shards.options.seedVoiceConnections && voiceState.user_id === client.user.id && !this.client.getVoiceConnection(this.id)) {
this.client.joinVoiceChannel({
guildID: this.id,
channelID: voiceState.channel_id,
selfDeaf: voiceState.self_deaf,
selfMute: voiceState.self_mute,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
voiceAdapterCreator: this.voiceAdapterCreator
});
}
}
}
}
toggleFeature(feature, enable, reason) {
const newFeatures = enable ?
(this.features.includes(feature) ? this.features : [...this.features, feature]) :
this.features.filter(name => name !== feature);
return this.edit({ features: newFeatures, reason });
}
// true = `memberCount`
updateMemberLimit(toAdd) {
if (this.members.limit === Infinity || this.client.options.disableMemberLimitScaling) {
return;
}
const original = this.members.limit;
const num = toAdd === true ? this.memberCount : this.members.limit + toAdd;
const round = 10 ** (Math.floor(Math.log10(num)) - 1);
if (toAdd === true) {
const limit = Math.round(num / round) * round + round;
if (this.members.limit >= limit) {
return;
}
this.members.limit = limit;
}
else {
const limit = Math.round((this.members.size + toAdd) / round) * round + round;
if (this.members.limit >= limit) {
return;
}
this.members.limit = limit;
}
this.client.emit("debug", `The limit of the members collection of guild ${this.id} has been updated from ${original} to ${this.members.limit} to accommodate at least ${toAdd === true ? this.memberCount : this.members.size + toAdd} members.`);
}
update(data) {
if (data.afk_channel_id !== undefined) {
this.afkChannel = data.afk_channel_id === null ? null : this.client.getChannel(data.afk_channel_id);
this.afkChannelID = data.afk_channel_id;
}
if (data.afk_timeout !== undefined) {
this.afkTimeout = data.afk_timeout;
}
if (data.application_id !== undefined) {
this.application = this.client["_application"] && data.application_id === null ? null : (this.client.application.id === data.application_id ? this.client.application : undefined);
this.applicationID = data.application_id;
}
if (data.approximate_member_count !== undefined) {
this.approximateMemberCount = data.approximate_member_count;
}
if (data.approximate_presence_count !== undefined) {
this.approximatePresenceCount = data.approximate_presence_count;
}
if (data.banner !== undefined) {
this.banner = data.banner;
}
if (data.default_message_notifications !== undefined) {
this.defaultMessageNotifications = data.default_message_notifications;
}
if (data.description !== undefined) {
this.description = data.description;
}
if (data.discovery_splash !== undefined) {
this.discoverySplash = data.discovery_splash;
}
if (data.emojis !== undefined) {
this.emojis.clear();
for (const emoji of data.emojis) {
this.emojis.update(emoji);
}
}
if (data.explicit_content_filter !== undefined) {
this.explicitContentFilter = data.explicit_content_filter;
}
if (data.features !== undefined) {
this.features = data.features;
}
if (data.icon !== undefined) {
this.icon = data.icon;
}
if (data.incident_actions !== undefined) {
this.incidentActions = {
dmsDisabledUntil: data.incident_actions.dms_disabled_until,
invitesDisabledUntil: data.incident_actions.invites_disabled_until
};
}
if (data.inventory_settings !== undefined) {
this.inventorySettings = data.inventory_settings === null ? null : {
isEmojiPackCollectible: data.inventory_settings.is_emoji_pack_collectible
};
}
if (data.joined_at !== undefined) {
this.joinedAt = data.joined_at === null ? null : new Date(data.joined_at);
}
if (data.large !== undefined) {
this.large = data.large;
}
if (data.latest_onboarding_question_id !== undefined) {
this.latestOnboardingQuestionID = data.latest_onboarding_question_id;
}
if (data.max_members !== undefined) {
this.maxMembers = data.max_members;
}
if (data.max_presences !== undefined) {
this.maxPresences = data.max_presences;
}
if (data.max_stage_video_channel_users !== undefined) {
this.maxStageVideoChannelUsers = data.max_stage_video_channel_users;
}
if (data.max_video_channel_users !== undefined) {
this.maxVideoChannelUsers = data.max_video_channel_users;
}
if (data.member_count !== undefined) {
this.memberCount = data.member_count;
}
if (data.mfa_level !== undefined) {
this.mfaLevel = data.mfa_level;
}
if (data.name !== undefined) {
this.name = data.name;
}
if (data.nsfw_level !== undefined) {
this.nsfwLevel = data.nsfw_level;
}
if (data.owner_id !== undefined) {
this.ownerID = data.owner_id;
this.owner = data.owner_id === null ? null : this.client.users.get(data.owner_id);
}
if (data.preferred_locale !== undefined) {
this.preferredLocale = data.preferred_locale;
}
if (data.premium_progress_bar_enabled !== undefined) {
this.premiumProgressBarEnabled = data.premium_progress_bar_enabled;
}
if (data.premium_subscription_count !== undefined) {
this.premiumSubscriptionCount = data.premium_subscription_count;
}
if (data.premium_tier !== undefined) {
this.premiumTier = data.premium_tier;
}
if (data.public_updates_channel_id !== undefined) {
this.publicUpdatesChannel = data.public_updates_channel_id === null ? null : this.client.getChannel(data.public_updates_channel_id);
this.publicUpdatesChannelID = data.public_updates_channel_id;
}
if (data.region !== undefined) {
this.region = data.region;
}
if (data.rules_channel_id !== undefined) {
this.rulesChannel = data.rules_channel_id === null ? null : this.client.getChannel(data.rules_channel_id);
this.rulesChannelID = data.rules_channel_id;
}
if (data.safety_alerts_channel_id !== undefined) {
this.safetyAlertsChannel = data.safety_alerts_channel_id === null ? null : this.client.getChannel(data.safety_alerts_channel_id);
this.safetyAlertsChannelID = data.safety_alerts_channel_id;
}
if (data.splash !== undefined) {
this.splash = data.splash;
}
if (data.stickers !== undefined) {
this.stickers.clear();
for (const sticker of data.stickers)
this.stickers.update(sticker);
}
if (data.system_channel_flags !== undefined) {
this.systemChannelFlags = data.system_channel_flags;
}
if (data.system_channel_id !== undefined) {
this.systemChannel = data.system_channel_id === null ? null : this.client.getChannel(data.system_channel_id);
this.systemChannelID = data.system_channel_id;
}
if (data.vanity_url_code !== undefined) {
this.vanityURLCode = data.vanity_url_code;
}
if (data.verification_level !== undefined) {
this.verificationLevel = data.verification_level;
}
if (data.welcome_screen !== undefined) {
this.welcomeScreen = {
description: data.welcome_screen.description,
welcomeChannels: data.welcome_screen.welcome_channels.map(channel => ({
channelID: channel.channel_id,
description: channel.description,
emojiID: channel.emoji_id,
emojiName: channel.emoji_name
}))
};
}
if (data.widget_channel_id !== undefined) {
this.widgetChannel = data.widget_channel_id === null ? null : this.client.getChannel(data.widget_channel_id);
this.widgetChannelID = data.widget_channel_id;
}
if (data.widget_enabled !== undefined) {
this.widgetEnabled = data.widget_enabled;
}
}
/** The client's member for this guild. This will throw an error if the member is not cached. */
get clientMember() {
this._clientMember ??= this.client["_user"] === undefined ? undefined : this.members.get(this.client["_user"].id);
if (!this._clientMember) {
if (this._rest) {
throw new Errors_1.UncachedError(`${this.constructor.name}#clientMember is not present when the guild is obtained via rest.`);
}
throw new Errors_1.UncachedError(`The client's member has not been cached for ${this.constructor.name}#clientMember.`);
}
return this._clientMember;
}
/** The shard this guild is on. Gateway only. */
get shard() {
this._shard ??= this.client.shards["_forGuild"](this.id);
if (this.client.options.restMode) {
throw new TypeError(`${this.constructor.name}#shard will not be present with rest mode enabled.`);
}
if (!this.client.shards.connected) {
throw new TypeError(`${this.constructor.name}#shard will not be present without a gateway connection.`);
}
if (!this._shard) {
throw new TypeError(`Failed to determine shard for ${this.constructor.name}#shard (guild: ${this.id})`);
}
return this._shard;
}
/** The voice adapter creator for this guild that can be used with [@discordjs/voice](https://discord.js.org/#/docs/voice/main/general/welcome) to play audio in voice and stage channels. */
get voiceAdapterCreator() {
this._shard ??= this.client.shards["_forGuild"](this.id);
if (this.client.options.restMode) {
throw new TypeError(`${this.constructor.name}#voiceAdapterCreator cannot be used with rest mode enabled.`);
}
if (!this.client.shards.connected) {
throw new TypeError(`${this.constructor.name}#shard cannot be used without a gateway connection.`);
}
if (!this._shard) {
throw new TypeError(`Failed to determine shard for ${this.constructor.name}#voiceAdapterCreator (guild: ${this.id})`);
}
return (methods) => {
this.client.voiceAdapters.set(this.id, methods);
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return {
sendPayload: (payload) => {
this.shard.send(payload.op, payload.d);
return true;
},
destroy: () => this.client.voiceAdapters.delete(this.id)
};
};
}
/**
* Add a member to this guild. Requires an access token with the `guilds.join` scope.
*
* Returns the newly added member upon success, or void if the member is already in the guild.
* @param userID The ID of the user to add.
* @param options The options for adding the member.
*/
async addMember(userID, options) {
return this.client.rest.guilds.addMember(this.id, userID, options);
}
/**
* Add a role to a member.
* @param memberID The ID of the member.
* @param roleID The ID of the role to add.
* @param reason The reason for adding the role.
*/
async addMemberRole(memberID, roleID, reason) {
return this.client.rest.guilds.addMemberRole(this.id, memberID, roleID, reason);
}
/**
* The url of this guild's banner.
* @param format The format the url should be.
* @param size The dimensions of the image.
*/
bannerURL(format, size) {
return this.banner === null ? null : this.client.util.formatImage(Routes.BANNER(this.id, this.banner), format, size);
}
/**
* Begin a prune.
* @param options The options for the prune.
*/
async beginPrune(options) {
return this.client.rest.guilds.beginPrune(this.id, options);
}
/**
* Ban up to 200 members from this guild. This requires both the `BAN_MEMBERS` and `MANAGE_GUILD` permissions.
* If no members were banned, a {@link Constants~JSONErrorCodes.FAILED_TO_BAN_USERS | FAILED_TO_BAN_USERS } will be returned.
* The bot user is ignored.
* @param options The options for banning.
*/
async bulkBan(options) {
return this.client.rest.guilds.bulkBan(this.id, options);
}
/**
* Create an auto moderation rule for this guild.
* @param options The options for the rule.
*/
async createAutoModerationRule(options) {
return this.client.rest.guilds.createAutoModerationRule(this.id, options);
}
/**
* Create a ban for a user.
* @param userID The ID of the user.
* @param options The options for creating the ban.
*/
async createBan(userID, options) {
return this.client.rest.guilds.createBan(this.id, userID, options);
}
/**
* Create a channel in this guild.
* @param options The options for creating the channel.
*/
async createChannel(type, options) {
return this.client.rest.guilds.createChannel(this.id, type, options);
}
/**
* Create an emoji in this guild.
* @param options The options for creating the emoji.
*/
async createEmoji(options) {
return this.client.rest.guilds.createEmoji(this.id, options);
}
/**
* Create a role.
* @param options The options for creating the role.
*/
async createRole(options) {
return this.client.rest.guilds.createRole(this.id, options);
}
/**
* Create a scheduled event in this guild.
* @param options The options for creating the scheduled event.
*/
async createScheduledEvent(options) {
return this.client.rest.guilds.createScheduledEvent(this.id, options);
}
/**
* Create a soundboard sound.
* @param options The options for creating the soundboard sound.
*/
async createSoundboardSound(options) {
return this.client.rest.guilds.createSoundboardSound(this.id, options);
}
/**
* Create a sticker.
* @param options The options for creating the sticker.
*/
async createSticker(options) {
return this.client.rest.guilds.createSticker(this.id, options);
}
/**
* Create a guild template.
* @param options The options for creating the template.
*/
async createTemplate(options) {
return this.client.rest.guilds.createTemplate(this.id, options);
}
/**
* Create a test entitlement for this guild.
* @param skuID The ID of the SKU to create an entitlement for.
* @param applicationID The ID of the application to create the entitlement for. If present, defaults to the logged in client's application id.
*/
async createTestEntitlement(skuID, applicationID) {
if (applicationID === undefined && this.client["_application"] === undefined) {
throw new Errors_1.UncachedError("Client#application is not present, you must provide an applicationID as a second argument. To not need to provide an ID, only call this after at least one shard is READY, or restMode is enabled.");
}
return this.client.rest.applications.createTestEntitlement(applicationID ?? this.client.application.id, {
ownerID: this.id,
ownerType: Constants_1.EntitlementOwnerTypes.GUILD,
skuID
});
}
/**
* Delete an auto moderation rule in this guild.
* @param ruleID The ID of the rule to delete.
* @param reason The reason for deleting the rule.
*/
async deleteAutoModerationRule(ruleID, reason) {
return this.client.rest.guilds.deleteAutoModerationRule(this.id, ruleID, reason);
}
/**
* Delete an emoji in this guild.
* @param emojiID The ID of the emoji.
* @param reason The reason for deleting the emoji.
*/
async deleteEmoji(emojiID, reason) {
return this.client.rest.guilds.deleteEmoji(this.id, emojiID, reason);
}
/**
* Delete an integration.
* @param integrationID The ID of the integration.
* @param reason The reason for deleting the integration.
*/
async deleteIntegration(integrationID, reason) {
return this.client.rest.guilds.deleteIntegration(this.id, integrationID, reason);
}
/**
* Delete a role.
* @param roleID The ID of the role to delete.
* @param reason The reason for deleting the role.
*/
async deleteRole(roleID, reason) {
return this.client.rest.guilds.deleteRole(this.id, roleID, reason);
}
/**
* Delete a scheduled event.
* @param eventID The ID of the scheduled event.
* @param reason The reason for deleting the scheduled event. Discord's docs do not explicitly state a reason can be provided, so it may not be used.
*/
async deleteScheduledEvent(eventID, reason) {
return this.client.rest.guilds.deleteScheduledEvent(this.id, eventID, reason);
}
/**
* Delete a soundboard sound.
* @param soundID The ID of the soundboard sound.
* @param reason The reason for deleting the soundboard sound.
*/
async deleteSoundboardSound(soundID, reason) {
return this.client.rest.guilds.deleteSoundboardSound(this.id, soundID, reason);
}
/**
* Delete a sticker.
* @param stickerID The ID of the sticker to delete.
* @param reason The reason for deleting the sticker.
*/
async deleteSticker(stickerID, reason) {
return this.client.rest.guilds.deleteSticker(this.id, stickerID, reason);
}
/**
* Delete a template.
* @param code The code of the template.
*/
async deleteTemplate(code) {
return this.client.rest.guilds.deleteTemplate(this.id, code);
}
/**
* Disable the `COMMUNITY` feature for this guild. Requires the **Administrator** permission.
* @param reason The reason for disable the feature.
*/
async disableCommunity(reason) {
return this.toggleFeature("COMMUNITY", false, reason);
}
/**
* Disable the `DISCOVERABLE` feature for this guild. Requires the **Administrator** permission.
* @param reason The reason for disabling the feature.
*/
async disableDiscovery(reason) {
return this.toggleFeature("DISCOVERABLE", false, reason);
}
/**
* Disable the `INVITES_DISABLED` feature for this guild. Requires the **Manage Guild** permission.
* @param reason The reason for disabling the feature.
*/
async disableInvites(reason) {
return this.toggleFeature("INVITES_DISABLED", true, reason);
}
/**
* Disable the `RAID_ALERTS_ENABLED` feature for this guild. Requires the **Manage Guild** permission.
* @param reason The reason for disabling the feature.
*/
async disableRaidAlerts(reason) {
return this.toggleFeature("RAID_ALERTS_ENABLED", false, reason);
}
/**
* The url of this guild's discovery splash.
* @param format The format the url should be.
* @param size The dimensions of the image.
*/
discoverySplashURL(format, size) {
return this.discoverySplash === null ? null : this.client.util.formatImage(Routes.GUILD_DISCOVERY_SPLASH(this.id, this.discoverySplash), format, size);
}
/**
* Edit this guild.
* @param options The options for editing the guild.
*/
async edit(options) {
return this.client.rest.guilds.edit(this.id, options);
}
/**
* Edit an existing auto moderation rule in this guild.
* @param ruleID The ID of the rule to edit.
* @param options The options for editing the rule.
*/
async editAutoModerationRule(ruleID, options) {
return this.client.rest.guilds.editAutoModerationRule(this.id, ruleID, options);
}
/**
* Edit the positions of channels in this guild.
* @param options The channels to move. Unedited channels do not need to be specified.
*/
async editChannelPositions(options) {
return this.client.rest.guilds.editChannelPositions(this.id, options);
}
/**
* Modify the current member in this guild.
* @param options The options for editing the member.
*/
async editCurrentMember(options) {
return this.client.rest.guilds.editCurrentMember(this.id, options);
}
/**
* Edit the current member's voice state in this guild. `channelID` is required, and the current member must already be in that channel. See [Discord's docs](https://discord.com/developers/docs/resources/guild#modify-current-user-voice-state-caveats) for more information.
* @param options The options for editing the voice state.
*/
async editCurrentUserVoiceState(options) {
return this.client.rest.guilds.editCurrentUserVoiceState(this.id, options);
}
/**
* Edit an existing emoji in this guild.
* @param options The options for editing the emoji.
*/
async editEmoji(emojiID, options) {
return this.client.rest.guilds.editEmoji(this.id, emojiID, options);
}
/**
* Edit the incident actions for this guild.
* @param options The options for editing the incident actions.
*/
async editIncidentActions(options) {
return this.client.rest.guilds.editIncidentActions(this.id, options);
}
/**
* Edit a member of this guild. Use \<Guild\>.editCurrentMember if you wish to update the nick of this client using the CHANGE_NICKNAME permission.
* @param memberID The ID of the member.
* @param options The options for editing the member.
*/
async editMember(memberID, options) {
return this.client.rest.guilds.editMember(this.id, memberID, options);
}
/**
* Edit this guild's onboarding configuration.
* @param options The options for editing the onboarding configuration.
*/
async editOnboarding(options) {
return this.client.rest.guilds.editOnboarding(this.id, options);
}
/**
* Edit an existing role.
* @param options The options for editing the role.
*/
async editRole(roleID, options) {
return this.client.rest.guilds.editRole(this.id, roleID, options);
}
/**
* Edit the position of roles in this guild.
* @param options The roles to move.
*/
async editRolePositions(options, reason) {
return this.client.rest.guilds.editRolePositions(this.id, options, reason);
}
/**
* Edit an existing scheduled event in this guild.
* @param scheduledEventID The ID of the scheduled event.
* @param options The options for editing the scheduled event.
*/
async editScheduledEvent(scheduledEventID, options) {
return this.client.rest.guilds.editScheduledEvent(this.id, scheduledEventID, options);
}
/**
* Edit a soundboard sound.
* @param soundID The ID of the soundboard sound.
* @param options The options for editing the soundboard sound.
*/
async editSoundboardSound(soundID, options) {
return this.client.rest.guilds.editSoundboardSound(this.id, soundID, options);
}
/**
* Edit a sticker.
* @param options The options for editing the sticker.
*/
async editSticker(stickerID, options) {
return this.client.rest.guilds.editSticker(this.id, stickerID, options);
}
/**
* Edit a template.
* @param code The code of the template.
* @param options The options for editing the template.
*/
async editTemplate(code, options) {
return this.client.rest.guilds.editTemplate(this.id, code, options);
}
/**
* Edit a guild member's voice state. `channelID` is required, and the user must already be in that channel. See [Discord's docs](https://discord.com/developers/docs/resources/guild#modify-user-voice-state) for more information.
* @param memberID The ID of the member.
* @param options The options for editing the voice state.
*/
async editUserVoiceState(memberID, options) {
return this.client.rest.guilds.editUserVoiceState(this.id, memberID, options);
}
/**
* Edit the welcome screen in this guild.
* @param options The options for editing the welcome screen.
*/
async editWelcomeScreen(options) {
return this.client.rest.guilds.editWelcomeScreen(this.id, options);
}
/**
* Edit the widget of this guild.
* @param options The options for editing the widget.
*/
async editWidget(options) {
return this.client.rest.guilds.editWidget(this.id, options);
}
/**
* Enable the `COMMUNITY` feature for this guild. Requires the **Administrator** permission.
* @param reason The reason for enabling the feature.
*/
async enableCommunity(reason) {
return this.toggleFeature("COMMUNITY", true, reason);
}
/**
* Enable the `DISCOVERABLE` feature for this guild. Requires the **Administrator** permission. The server must also be passing all discovery requirements.
* @param reason The reason for enabling the feature.
*/
async enableDiscovery(reason) {
return this.toggleFeature("DISCOVERABLE", true, reason);
}
/**
* Enable the `INVITES_DISABLED` feature for this guild. Requires the **Manage Guild** permission.
* @param reason The reason for enabling the feature.
*/
async enableInvites(reason) {
return this.toggleFeature("INVITES_DISABLED", false, reason);
}
/**
* Enable the `RAID_ALERTS_ENABLED` feature for this guild. Requires the **Manage Guild** permission.
* @param reason The reason for enabling the feature.
*/
async enableRaidAlerts(reason) {
return this.toggleFeature("RAID_ALERTS_ENABLED", true, reason);
}
/**
* Request members from this guild.
* @param options The options for fetching the members.
*/
async fetchMembers(options) {
return this.shard.requestGuildMembers(this.id, options);
}
/**
* Get the active threads in this guild.
*/
async getActiveThreads() {
return this.client.rest.guilds.getActiveThreads(this.id);
}
/**
* Get this guild's audit log.
* @param options The options for the audit log.
*/
async getAuditLog(options) {
return this.client.rest.guilds.getAuditLog(this.id, options);
}
/**
* Get an auto moderation rule for this guild.
* @param ruleID The ID of the rule to get.
*/
async getAutoModerationRule(ruleID) {
return this.client.rest.guilds.getAutoModerationRule(this.id, ruleID);
}
/**
* Get the auto moderation rules for this guild.
*/
async getAutoModerationRules() {
return this.client.rest.guilds.getAutoModerationRules(this.id);
}
/**
* Get a ban in this guild.
* @param userID The ID of the user to get the ban of.
*/
async getBan(userID) {
return this.client.rest.guilds.getBan(this.id, userID);
}
/**
* Get the bans in this guild.
* @param options The options for getting the bans.
*/
async getBans(options) {
return this.client.rest.guilds.getBans(this.id, options);
}
/**
* Get the channels in a guild. Does not include threads. Only use this if you need to. See the `channels` collection.
*/
async getChannels() {
return this.client.rest.guilds.getChannels(this.id);
}
/**
* Get an emoji in this guild.
* @param emojiID The ID of the emoji to get.
*/
async getEmoji(emojiID) {
return this.client.rest.guilds.getEmoji(this.id, emojiID);
}
/**
* Get the emojis in this guild.
*/
async getEmojis() {
return this.client.rest.guilds.getEmojis(this.id);
}
/**
* Get the entitlements for this guild.
* @param options The options for getting the entitlements.
* @param applicationID The ID of the application to create the entitlement for. If present, defaults to the logged in client's application id.
*/
async getEntitlements(options, applicationID) {
if (applicationID === undefined && this.client["_application"] === undefined) {
throw new Errors_1.UncachedError("Client#application is not present, you must provide an applicationID as a second argument. To not need to provide an ID, only call this after at least one shard is READY, or restMode is enabled.");
}
return this.client.rest.applications.getEntitlements(applicationID ?? this.client.application.id, { guildID: this.id, ...options });
}
/**
* Get the integrations in this guild.
*/
async getIntegrations() {
return this.client.rest.guilds.getIntegrations(this.id);
}
/**
* Get the invites of this guild.
*/
async getInvites() {
return this.client.rest.guilds.getInvites(this.id);
}
/**
* Get a member of this guild.
* @param memberID The ID of the member.
*/
async getMember(memberID) {
return this.client.rest.guilds.getMember(this.id, memberID);
}
/**
* Get this guild's members. This requires the `GUILD_MEMBERS` intent.
* @param options The options for getting the members.
*/
async getMembers(options) {
return this.client.rest.guilds.getMembers(this.id, options);
}
/**
* Get the onboarding information for this guild.
*/
async getOnboarding() {
return this.client.rest.guilds.getOnboarding(this.id);
}
/**
* Get a preview of this guild.
*/
async getPreview() {
return this.client.rest.guilds.getPreview(this.id);
}
/**
* Get the prune count of this guild.
* @param options The options for getting the prune count.
*/
async getPruneCount(options) {
return this.client.rest.guilds.getPruneCount(this.id, options);
}
/**
* Get a role in this guild. Only use this if you need to. See the `roles` collection.
* @param roleID The ID of the role to get.
*/
async getRole(roleID) {
return this.client.rest.guilds.getRole(this.id, roleID);
}
/**
* Get the roles in this guild. Only use this if you need to. See the `roles` collection.
*/
async getRoles() {
return this.client.rest.guilds.getRoles(this.id);
}
/**
* Get a scheduled event.
* @param eventID The ID of the scheduled event to get.
* @param withUserCount If the number of users subscribed to the event should be included.
*/
async getScheduledEvent(eventID, withUserCount) {
return this.client.rest.guilds.getScheduledEvent(this.id, eventID, withUserCount);
}
/**
* Get the users subscribed to a scheduled event.
* @param eventID The ID of the scheduled event to get the users of.
* @param options The options for getting the users.
*/
async getScheduledEventUsers(eventID, options) {
return this.client.rest.guilds.getScheduledEventUsers(this.id, eventID, options);
}
/**
* Get this guild's scheduled events
* @param withUserCount If the number of users subscribed to the event should be included.
*/
async getScheduledEvents(withUserCount) {
return this.client.rest.guilds.getScheduledEvents(this.id, withUserCount);
}
/**
* Get a soundboard sound.
* @param soundID The ID of the soundboard sound to get.
*/
async getSoundboardSound(soundID) {
return this.client.rest.guilds.getSoundboardSound(this.id, soundID);
}
/**
* Get this guild's soundboard sounds.
*/
async getSoundboardSounds() {
return this.client.rest.guilds.getSoundboardSounds(this.id);
}
/**
* Get a sticker. Response will include a user if the client has the `MANAGE_EMOJIS_AND_STICKERS` permissions.
* @param stickerID The ID of the sticker to get.
*/
async getSticker(stickerID) {
return this.client.rest.guilds.getSticker(this.id, stickerID);
}
/**
* Get this guild's stickers. Stickers will include a user if the client has the `MANAGE_EMOJIS_AND_STICKERS` permissions.
*/
async getStickers() {
return this.client.rest.guilds.getStickers(this.id);
}
/**
* Get this guild's templates.
*/
async getTemplates() {
return this.client.rest.guilds.getTemplates(this.id);
}
/**
* Get the vanity url of this guild.
*/
async getVanityURL() {
return this.client.rest.guilds.getVanityURL(this.id);
}
/**