Guild
classe · Source
Represents a guild (or a server) on Discord. It's recommended to see if a guild is available before performing operations or reading data from it. You can check this with Guild#available.
Extends: AnonymousGuild
Properties
members
A manager of the members belonging to this guild Source
channels
A manager of the channels belonging to this guild Source
bans
A manager of the bans belonging to this guild Source
roles
A manager of the roles belonging to this guild Source
presences
A manager of the presences belonging to this guild Source
voiceStates
A manager of the voice states of this guild Source
stageInstances
A manager of the stage instances of this guild Source
invites
A manager of the invites of this guild Source
scheduledEvents
A manager of the scheduled events of this guild Source
autoModerationRules
A manager of the auto moderation rules of this guild. Source
settings
All of the settings ObjectSource
available
Whether the guild is available to access. If it is not available, it indicates a server outage Source
shardId
The id of the shard this Guild belongs to. Source
deleted
Whether or not the structure has been deleted Source
shard
The Shard this Guild belongs to. Source
discoverySplash
The hash of the guild discovery splash image Source
memberCount
The full amount of members in this guild Source
large
Whether the guild is "large" (has more than large_threshold members, 50 by default) Source
premiumProgressBarEnabled
Whether this guild has its premium (boost) progress bar enabled Source
applicationId
The id of the application that created this guild (if applicable) Source
afkTimeout
The time in seconds before a user is counted as "away from keyboard" Source
afkChannelId
The id of the voice channel where AFK members are moved Source
systemChannelId
The system channel's id Source
premiumTier
The premium tier of this guild Source
widgetEnabled
Whether widget images are enabled on this guild Source
widgetChannelId
The widget channel's id, if enabled Source
explicitContentFilter
The explicit content filter level of the guild Source
mfaLevel
The required MFA level for this guild Source
joinedTimestamp
The timestamp the client user joined the guild at Source
defaultMessageNotifications
The default message notification level of the guild Source
systemChannelFlags
The value set for the guild's system channel flags Source
maximumMembers
The maximum amount of members the guild can have Source
maximumPresences
The maximum amount of presences the guild can have You will need to fetch the guild using Guild#fetch if you want to receive this parameter Source
maxVideoChannelUsers
The maximum amount of users allowed in a video channel. Source
maxStageVideoChannelUsers
The maximum amount of users allowed in a stage video channel. Source
approximateMemberCount
The approximate amount of members the guild has You will need to fetch the guild using Guild#fetch if you want to receive this parameter Source
approximatePresenceCount
The approximate amount of presences the guild has You will need to fetch the guild using Guild#fetch if you want to receive this parameter Source
vanityURLUses
The use count of the vanity URL code of the guild, if any You will need to fetch this parameter using Guild#fetchVanityData if you want to receive it Source
rulesChannelId
The rules channel's id for the guild Source
publicUpdatesChannelId
The community updates channel's id for the guild Source
preferredLocale
The preferred locale of the guild, defaults to en-USSource
safetyAlertsChannelId
The safety alerts channel's id for the guild Source
ownerId
The user id of this guild's owner Source
emojis
A manager of the emojis belonging to this guild Source
stickers
A manager of the stickers belonging to this guild Source
incidentsData
The incidents data of this guild. You will need to fetch the guild using BaseGuild#fetch if you want to receive this property. Source
joinedAt
The time the client user joined the guild Source
afkChannel
AFK voice channel for this guild Source
systemChannel
System channel for this guild Source
safetyAlertsChannel
Safety alerts channel for this guild Source
widgetChannel
Widget channel for this guild Source
rulesChannel
Rules channel for this guild Source
publicUpdatesChannel
Public updates channel for this guild Source
me
The client user as a GuildMember of this guild Source
maximumBitrate
The maximum bitrate available for this guild Source
maximumStageBitrate
The maximum bitrate available for a stage channel in this guild. Source
voiceAdapterCreator
The voice state adapter for this guild that can be used with @discordjs/voice to play audio in voice and stage channels. Source
splash
The hash of the guild invite splash image Source
banner
The hash of the guild banner Source
description
The description of the guild, if any Source
verificationLevel
The verification level of the guild Source
vanityURLCode
The vanity invite code of the guild, if any Source
nsfwLevel
The NSFW level of this guild Source
premiumSubscriptionCount
The total number of boosts for this server Source
id
The guild's id Source
name
The name of this guild Source
icon
The icon hash of this guild Source
features
An array of features available to this guild Source
createdTimestamp
The timestamp this guild was created at Source
createdAt
The time this guild was created at Source
nameAcronym
The acronym that shows up in place of a guild icon Source
partnered
Whether this guild is partnered Source
verified
Whether this guild is verified Source
client
The client that instantiated this Source
Methods
discoverySplashURL
The URL to this guild's discovery splash image. Parameters
| Name | Type | Description |
|---|---|---|
options? | StaticImageURLOptions | Options for the Image URL Default: {}. |
Returns: stringSource
fetchOwner
Fetches the owner of the guild. If the member object isn't needed, use Guild#ownerId instead. Parameters
| Name | Type | Description |
|---|---|---|
options? | BaseFetchOptions | The options for fetching the member |
Returns: Promise<GuildMember>Source
fetchIntegrations
Fetches a collection of integrations to this guild. Resolves with a collection mapping integrations by their ids. Returns: Promise<Collection<(Snowflake\|string), Integration>>
// Fetch integrations
guild.fetchIntegrations()
.then(integrations => console.log(`Fetched ${integrations.size} integrations`))
.catch(console.error);fetchTemplates
Fetches a collection of templates from this guild. Resolves with a collection mapping templates by their codes. Returns: Promise<Collection<string, GuildTemplate>>Source
fetchWelcomeScreen
Fetches the welcome screen for this guild. Returns: Promise<WelcomeScreen>Source
createTemplate
Creates a template for the guild. Parameters
| Name | Type | Description |
|---|---|---|
name | string | The name for the template |
description? | string | The description for the template |
Returns: Promise<GuildTemplate>Source
fetchPreview
Obtains a guild preview for this guild from Discord. Returns: Promise<GuildPreview>Source
fetchVanityData
Fetches the vanity URL invite object to this guild. Resolves with an object containing the vanity URL invite code and the use count Returns: Promise<Vanity>
// Fetch invite data
guild.fetchVanityData()
.then(res => {
console.log(`Vanity URL: https://discord.gg/${res.code} with ${res.uses} uses`);
})
.catch(console.error);fetchWebhooks
Fetches all webhooks for the guild. Returns: Promise<Collection<Snowflake, Webhook>>
// Fetch webhooks
guild.fetchWebhooks()
.then(webhooks => console.log(`Fetched ${webhooks.size} webhooks`))
.catch(console.error);fetchWidget
Fetches the guild widget data, requires the widget to be enabled. Returns: Promise<Widget>
// Fetches the guild widget data
guild.fetchWidget()
.then(widget => console.log(`The widget shows ${widget.channels.size} channels`))
.catch(console.error);fetchWidgetSettings
Fetches the guild widget settings. Returns: Promise<GuildWidgetSettings>
// Fetches the guild widget settings
guild.fetchWidgetSettings()
.then(widget => console.log(`The widget is ${widget.enabled ? 'enabled' : 'disabled'}`))
.catch(console.error);fetchAuditLogs
Fetches audit logs for this guild. Parameters
| Name | Type | Description |
|---|---|---|
options? | GuildAuditLogsFetchOptions | Options for fetching audit logs Default: {}. |
Returns: Promise<GuildAuditLogs>
// Output audit log entries
guild.fetchAuditLogs()
.then(audit => console.log(audit.entries.first()))
.catch(console.error);edit
Updates the guild with new information - e.g. a new name. Parameters
| Name | Type | Description |
|---|---|---|
data | GuildEditData | The data to update the guild with |
reason? | string | Reason for editing this guild |
Returns: Promise<Guild>
// Set the guild name
guild.edit({
name: 'Discord Guild',
})
.then(updated => console.log(`New guild name ${updated}`))
.catch(console.error);editWelcomeScreen
Updates the guild's welcome screen Parameters
| Name | Type | Description |
|---|---|---|
data | WelcomeScreenEditData | Data to edit the welcome screen with |
Returns: Promise<WelcomeScreen>
guild.editWelcomeScreen({
description: 'Hello World',
enabled: true,
welcomeChannels: [
{
description: 'foobar',
channel: '222197033908436994',
}
],
})setExplicitContentFilter
Edits the level of the explicit content filter. Parameters
| Name | Type | Description |
|---|---|---|
explicitContentFilter | ExplicitContentFilterLevel | number | The new level of the explicit content filter |
reason? | string | Reason for changing the level of the guild's explicit content filter |
Returns: Promise<Guild>Source
setDefaultMessageNotifications
Edits the setting of the default message notifications of the guild. Parameters
| Name | Type | Description |
|---|---|---|
defaultMessageNotifications | DefaultMessageNotificationLevel | number | The new default message notification level of the guild |
reason? | string | Reason for changing the setting of the default message notifications |
Returns: Promise<Guild>Source
setSystemChannelFlags
Edits the flags of the default message notifications of the guild. Parameters
| Name | Type | Description |
|---|---|---|
systemChannelFlags | SystemChannelFlagsResolvable | The new flags for the default message notifications |
reason? | string | Reason for changing the flags of the default message notifications |
Returns: Promise<Guild>Source
setName
Edits the name of the guild. Parameters
| Name | Type | Description |
|---|---|---|
name | string | The new name of the guild |
reason? | string | Reason for changing the guild's name |
Returns: Promise<Guild>
// Edit the guild name
guild.setName('Discord Guild')
.then(updated => console.log(`Updated guild name to ${updated.name}`))
.catch(console.error);setVerificationLevel
Edits the verification level of the guild. Parameters
| Name | Type | Description |
|---|---|---|
verificationLevel | VerificationLevel | number | The new verification level of the guild |
reason? | string | Reason for changing the guild's verification level |
Returns: Promise<Guild>
// Edit the guild verification level
guild.setVerificationLevel(1)
.then(updated => console.log(`Updated guild verification level to ${guild.verificationLevel}`))
.catch(console.error);setAFKChannel
Edits the AFK channel of the guild. Parameters
| Name | Type | Description |
|---|---|---|
afkChannel | VoiceChannelResolvable | The new AFK channel |
reason? | string | Reason for changing the guild's AFK channel |
Returns: Promise<Guild>
// Edit the guild AFK channel
guild.setAFKChannel(channel)
.then(updated => console.log(`Updated guild AFK channel to ${guild.afkChannel.name}`))
.catch(console.error);setSystemChannel
Edits the system channel of the guild. Parameters
| Name | Type | Description |
|---|---|---|
systemChannel | TextChannelResolvable | The new system channel |
reason? | string | Reason for changing the guild's system channel |
Returns: Promise<Guild>
// Edit the guild system channel
guild.setSystemChannel(channel)
.then(updated => console.log(`Updated guild system channel to ${guild.systemChannel.name}`))
.catch(console.error);setAFKTimeout
Edits the AFK timeout of the guild. Parameters
| Name | Type | Description |
|---|---|---|
afkTimeout | number | The time in seconds that a user must be idle to be considered AFK |
reason? | string | Reason for changing the guild's AFK timeout |
Returns: Promise<Guild>
// Edit the guild AFK channel
guild.setAFKTimeout(60)
.then(updated => console.log(`Updated guild AFK timeout to ${guild.afkTimeout}`))
.catch(console.error);setIcon
Sets a new guild icon. Parameters
| Name | Type | Description |
|---|---|---|
icon | Base64Resolvable | BufferResolvable | The new icon of the guild |
reason? | string | Reason for changing the guild's icon |
Returns: Promise<Guild>
// Edit the guild icon
guild.setIcon('./icon.png')
.then(updated => console.log('Updated the guild icon'))
.catch(console.error);setOwner
Sets a new owner of the guild. Parameters
| Name | Type | Description |
|---|---|---|
owner | GuildMemberResolvable | The new owner of the guild |
reason? | string | Reason for setting the new owner |
Returns: Promise<Guild>
// Edit the guild owner
guild.setOwner(guild.members.cache.first())
.then(guild => guild.fetchOwner())
.then(owner => console.log(`Updated the guild owner to ${owner.displayName}`))
.catch(console.error);setSplash
Sets a new guild invite splash image. Parameters
| Name | Type | Description |
|---|---|---|
splash | Base64Resolvable | BufferResolvable | The new invite splash image of the guild |
reason? | string | Reason for changing the guild's invite splash image |
Returns: Promise<Guild>
// Edit the guild splash
guild.setSplash('./splash.png')
.then(updated => console.log('Updated the guild splash'))
.catch(console.error);setDiscoverySplash
Sets a new guild discovery splash image. Parameters
| Name | Type | Description |
|---|---|---|
discoverySplash | Base64Resolvable | BufferResolvable | The new discovery splash image of the guild |
reason? | string | Reason for changing the guild's discovery splash image |
Returns: Promise<Guild>
// Edit the guild discovery splash
guild.setDiscoverySplash('./discoverysplash.png')
.then(updated => console.log('Updated the guild discovery splash'))
.catch(console.error);setBanner
Sets a new guild banner. Parameters
| Name | Type | Description |
|---|---|---|
banner | Base64Resolvable | BufferResolvable | The new banner of the guild |
reason? | string | Reason for changing the guild's banner |
Returns: Promise<Guild>
guild.setBanner('./banner.png')
.then(updated => console.log('Updated the guild banner'))
.catch(console.error);setRulesChannel
Edits the rules channel of the guild. Parameters
| Name | Type | Description |
|---|---|---|
rulesChannel | TextChannelResolvable | The new rules channel |
reason? | string | Reason for changing the guild's rules channel |
Returns: Promise<Guild>
// Edit the guild rules channel
guild.setRulesChannel(channel)
.then(updated => console.log(`Updated guild rules channel to ${guild.rulesChannel.name}`))
.catch(console.error);setPublicUpdatesChannel
Edits the community updates channel of the guild. Parameters
| Name | Type | Description |
|---|---|---|
publicUpdatesChannel | TextChannelResolvable | The new community updates channel |
reason? | string | Reason for changing the guild's community updates channel |
Returns: Promise<Guild>
// Edit the guild community updates channel
guild.setPublicUpdatesChannel(channel)
.then(updated => console.log(`Updated guild community updates channel to ${guild.publicUpdatesChannel.name}`))
.catch(console.error);setPreferredLocale
Edits the preferred locale of the guild. Parameters
| Name | Type | Description |
|---|---|---|
preferredLocale | string | The new preferred locale of the guild |
reason? | string | Reason for changing the guild's preferred locale |
Returns: Promise<Guild>
// Edit the guild preferred locale
guild.setPreferredLocale('en-US')
.then(updated => console.log(`Updated guild preferred locale to ${guild.preferredLocale}`))
.catch(console.error);setSafetyAlertsChannel
Edits the safety alerts channel of the guild. Parameters
| Name | Type | Description |
|---|---|---|
safetyAlertsChannel | TextChannelResolvable | The new safety alerts channel |
reason? | string | Reason for changing the guild's safety alerts channel |
Returns: Promise<Guild>
// Edit the guild safety alerts channel
guild.setSafetyAlertsChannel(channel)
.then(updated => console.log(`Updated guild safety alerts channel to ${updated.safetyAlertsChannel.name}`))
.catch(console.error);setPremiumProgressBarEnabled
Edits the enabled state of the guild's premium progress bar Parameters
| Name | Type | Description |
|---|---|---|
enabled? | boolean | The new enabled state of the guild's premium progress bar Default: true. |
reason? | string | Reason for changing the state of the guild's premium progress bar |
Returns: Promise<Guild>Source
setChannelPositions
Batch-updates the guild's channels' positions. Only one channel's parent can be changed at a time Parameters
| Name | Type | Description |
|---|---|---|
channelPositions | Array<ChannelPosition> | Channel positions to update |
Returns: Promise<Guild>
guild.setChannelPositions([{ channel: channelId, position: newChannelIndex }])
.then(guild => console.log(`Updated channel positions for ${guild}`))
.catch(console.error);setRolePositions
Batch-updates the guild's role positions Parameters
| Name | Type | Description |
|---|---|---|
rolePositions | Array<GuildRolePosition> | Role positions to update |
Returns: Promise<Guild>
guild.setRolePositions([{ role: roleId, position: updatedRoleIndex }])
.then(guild => console.log(`Role positions updated for ${guild}`))
.catch(console.error);setWidgetSettings
Edits the guild's widget settings. Parameters
| Name | Type | Description |
|---|---|---|
settings | GuildWidgetSettingsData | The widget settings for the guild |
reason? | string | Reason for changing the guild's widget settings |
Returns: Promise<Guild>Source
disableInvites
Sets whether this guild's invites are disabled. Parameters
| Name | Type | Description |
|---|---|---|
disabled? | boolean | Whether the invites are disabled Default: true. |
Returns: Promise<Guild>Source
setIncidentActions
Sets the incident actions for a guild. Parameters
| Name | Type | Description |
|---|---|---|
incidentActions | IncidentActionsEditOptions | The incident actions to set |
Returns: Promise<IncidentActions>Source
leave
Leaves the guild. Returns: Promise<Guild>
// Leave a guild
guild.leave()
.then(guild => console.log(`Left the guild: ${guild.name}`))
.catch(console.error);delete
Deletes the guild. Returns: Promise<Guild>
// Delete a guild
guild.delete()
.then(g => console.log(`Deleted the guild ${g}`))
.catch(console.error);equals
Whether this guild equals another guild. It compares all properties, so for most operations it is advisable to just compare guild.id === guild2.id as it is much faster and is often what most users need. Parameters
| Name | Type | Description |
|---|---|---|
guild | Guild | The guild to compare with |
Returns: booleanSource
markAsRead
Marks the guild as read. Returns: Promise<void>
const guild = client.guilds.cache.get('id');
guild.markAsRead();setCommunity
Set Community Feature. Parameters
| Name | Type | Description |
|---|---|---|
stats | boolean | True / False to enable / disable Community Feature Default: true. |
publicUpdatesChannel? | GuildTextChannelResolvable | The community updates channel of the guild |
rulesChannel? | GuildTextChannelResolvable | The new rules channel |
reason? | string | Reason for changing the community feature |
Returns: Promise<Guild>Source
topEmojis
Get the top emojis of this guild. Returns: Promise<Collection<number, GuildEmoji>>Source
setVanityCode
Set the vanity URL to this guild. Resolves with an object containing the vanity URL invite code and the use count. Parameters
| Name | Type | Description |
|---|---|---|
code? | string | Vanity URL code Default: ''. |
Returns: Promise<Vanity>
// Set invite code
guild.setVanityCode('elysia', '123456')
.then(res => {
console.log(`Vanity URL: https://discord.gg/${res.code} with ${res.uses} uses`);
})
.catch(console.error);requestChannelInfo
Requests ephemeral voice channel information for this guild. Discord responds with a CHANNEL_INFO Gateway dispatch. Parameters
| Name | Type | Description |
|---|---|---|
fields? | Array<('status'|'voice_start_time')> | Fields to request |
Returns: GuildSource
_sortedRoles
Creates a collection of this guild's roles, sorted by their position and ids. Returns: Collection<Snowflake, Role>Source
_sortedChannels
Creates a collection of this guild's or a specific category's channels, sorted by their position and ids. Parameters
| Name | Type | Description |
|---|---|---|
channel? | GuildChannel | Category to get the channels of |
Returns: Collection<Snowflake, GuildChannel>Source
bannerURL
The URL to this guild's banner. Parameters
| Name | Type | Description |
|---|---|---|
options? | StaticImageURLOptions | Options for the Image URL Default: {}. |
Returns: stringSource
splashURL
The URL to this guild's invite splash image. Parameters
| Name | Type | Description |
|---|---|---|
options? | StaticImageURLOptions | Options for the Image URL Default: {}. |
Returns: stringSource
iconURL
The URL to this guild's icon. Parameters
| Name | Type | Description |
|---|---|---|
options? | ImageURLOptions | Options for the Image URL Default: {}. |
Returns: stringSource
fetch
Fetches this guild. Returns: Promise<Guild>Source
toString
When concatenated with a string, this automatically returns the guild's name instead of the Guild object. Returns: stringSource