A powerful Node.js library for interacting with the Discord API, enabling developers to create Discord bots and applications with full API coverage
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Comprehensive guild (server) management functionality including channels, members, roles, permissions, moderation, and administrative features for Discord servers.
Represents a Discord guild (server) with full management capabilities.
/**
* Represents a Discord guild (server)
* @extends AnonymousGuild
*/
class Guild extends AnonymousGuild {
// Core properties
readonly id: Snowflake;
readonly name: string;
readonly description: string | null;
readonly ownerId: Snowflake;
readonly memberCount: number;
readonly large: boolean;
readonly premiumTier: GuildPremiumTier;
readonly premiumSubscriptionCount: number | null;
readonly available: boolean;
readonly createdAt: Date;
// Managers
readonly channels: GuildChannelManager;
readonly members: GuildMemberManager;
readonly roles: RoleManager;
readonly bans: GuildBanManager;
readonly invites: GuildInviteManager;
readonly scheduledEvents: GuildScheduledEventManager;
readonly stickers: GuildStickerManager;
readonly emojis: GuildEmojiManager;
readonly commands: GuildApplicationCommandManager;
readonly autoModerationRules: AutoModerationRuleManager;
// Guild management
edit(options: GuildEditOptions): Promise<Guild>;
delete(): Promise<Guild>;
leave(): Promise<Guild>;
// Member management
fetchOwner(options?: BaseFetchOptions): Promise<GuildMember>;
fetchMembers(options?: GuildFetchMembersOptions): Promise<Collection<Snowflake, GuildMember>>;
// Moderation
fetchBans(options?: GuildFetchBansOptions): Promise<Collection<Snowflake, GuildBan>>;
fetchBan(user: UserResolvable, options?: BaseFetchOptions): Promise<GuildBan>;
// Utility methods
fetchPreview(): Promise<GuildPreview>;
fetchTemplates(): Promise<Collection<string, GuildTemplate>>;
fetchWebhooks(): Promise<Collection<Snowflake, Webhook>>;
fetchAuditLogs(options?: GuildAuditLogsFetchOptions): Promise<GuildAuditLogs>;
fetchWidget(): Promise<Widget>;
setMFALevel(level: GuildMFALevel, reason?: string): Promise<Guild>;
// Icon and banner URLs
iconURL(options?: ImageURLOptions): string | null;
bannerURL(options?: ImageURLOptions): string | null;
splashURL(options?: ImageURLOptions): string | null;
discoverySplashURL(options?: ImageURLOptions): string | null;
}
interface GuildEditOptions {
name?: string;
description?: string | null;
verificationLevel?: GuildVerificationLevel | null;
explicitContentFilter?: GuildExplicitContentFilter | null;
defaultMessageNotifications?: GuildDefaultMessageNotifications | null;
afkChannel?: VoiceChannelResolvable | null;
systemChannel?: TextChannelResolvable | null;
afkTimeout?: number;
icon?: BufferResolvable | Base64Resolvable | null;
owner?: GuildMemberResolvable;
banner?: BufferResolvable | Base64Resolvable | null;
splash?: BufferResolvable | Base64Resolvable | null;
discoverySplash?: BufferResolvable | Base64Resolvable | null;
rulesChannel?: TextChannelResolvable | null;
publicUpdatesChannel?: TextChannelResolvable | null;
preferredLocale?: Locale | null;
premiumProgressBarEnabled?: boolean;
reason?: string;
}Usage Examples:
// Edit guild settings
await guild.edit({
name: 'New Server Name',
description: 'Updated server description',
verificationLevel: GuildVerificationLevel.Medium
});
// Fetch all members (requires privileged intent)
const members = await guild.members.fetch();
// Get guild owner
const owner = await guild.fetchOwner();
// Check guild features
if (guild.features.includes(GuildFeature.Community)) {
console.log('This is a community server');
}Represents a user's membership in a specific guild with roles and permissions.
/**
* Represents a guild member
* @extends Base
*/
class GuildMember extends Base {
readonly guild: Guild;
readonly user: User;
readonly roles: GuildMemberRoleManager;
readonly voice: VoiceState;
readonly permissions: Readonly<PermissionsBitField>;
readonly permissionsIn: (channel: GuildChannelResolvable) => Readonly<PermissionsBitField>;
// Member properties
readonly joinedAt: Date | null;
readonly premiumSince: Date | null;
readonly nickname: string | null;
readonly displayName: string;
readonly displayAvatarURL: (options?: ImageURLOptions) => string;
readonly communicationDisabledUntil: Date | null;
readonly flags: Readonly<GuildMemberFlagsBitField>;
// Member management
edit(options: GuildMemberEditOptions): Promise<GuildMember>;
kick(reason?: string): Promise<GuildMember>;
ban(options?: BanOptions): Promise<GuildMember>;
timeout(timeout: number | null, reason?: string): Promise<GuildMember>;
// Permission checks
hasPermission(permission: PermissionResolvable, checkAdmin?: boolean): boolean;
isCommunicationDisabled(): boolean;
// Avatar and display
avatarURL(options?: ImageURLOptions): string | null;
setNickname(nickname: string | null, reason?: string): Promise<GuildMember>;
}
interface GuildMemberEditOptions {
nick?: string | null;
roles?: Collection<Snowflake, Role> | RoleResolvable[];
mute?: boolean;
deaf?: boolean;
channel?: GuildVoiceChannelResolvable | null;
communicationDisabledUntil?: DateResolvable | null;
flags?: GuildMemberFlagsResolvable;
reason?: string;
}
interface BanOptions {
deleteMessageSeconds?: number;
reason?: string;
}Represents a Discord role with permissions and display properties.
/**
* Represents a Discord role
* @extends Base
*/
class Role extends Base {
readonly guild: Guild;
readonly id: Snowflake;
readonly name: string;
readonly color: number;
readonly hoist: boolean;
readonly position: number;
readonly permissions: Readonly<PermissionsBitField>;
readonly managed: boolean;
readonly mentionable: boolean;
readonly createdAt: Date;
readonly hexColor: string;
readonly unicodeEmoji: string | null;
readonly icon: string | null;
readonly tags: RoleTags | null;
readonly flags: Readonly<RoleFlagsBitField>;
// Role management
edit(options: RoleEditOptions): Promise<Role>;
delete(reason?: string): Promise<Role>;
setName(name: string, reason?: string): Promise<Role>;
setColor(color: ColorResolvable, reason?: string): Promise<Role>;
setHoist(hoist?: boolean, reason?: string): Promise<Role>;
setMentionable(mentionable?: boolean, reason?: string): Promise<Role>;
setPermissions(permissions: PermissionResolvable, reason?: string): Promise<Role>;
setPosition(position: number, reason?: string): Promise<Role>;
setIcon(icon: BufferResolvable | Base64Resolvable | EmojiResolvable | null, reason?: string): Promise<Role>;
setUnicodeEmoji(unicodeEmoji: string | null, reason?: string): Promise<Role>;
// Utility methods
iconURL(options?: ImageURLOptions): string | null;
comparePositionTo(role: RoleResolvable): number;
toString(): string;
}
interface RoleEditOptions {
name?: string;
color?: ColorResolvable;
hoist?: boolean;
permissions?: PermissionResolvable;
position?: number;
mentionable?: boolean;
icon?: BufferResolvable | Base64Resolvable | EmojiResolvable | null;
unicodeEmoji?: string | null;
reason?: string;
}Guild channel types and management functionality.
/**
* Base class for guild channels
* @extends BaseChannel
*/
class GuildChannel extends BaseChannel {
readonly guild: Guild;
readonly guildId: Snowflake;
readonly permissionOverwrites: PermissionOverwriteManager;
readonly viewable: boolean;
readonly deletable: boolean;
readonly manageable: boolean;
readonly position: number;
readonly parent: CategoryChannel | null;
readonly parentId: Snowflake | null;
edit(options: GuildChannelEditOptions): Promise<this>;
delete(reason?: string): Promise<this>;
setName(name: string, reason?: string): Promise<this>;
setParent(channel: CategoryChannelResolvable | null, options?: SetParentOptions): Promise<this>;
setPosition(position: number, options?: SetChannelPositionOptions): Promise<this>;
permissionsFor(memberOrRole: GuildMemberResolvable | RoleResolvable): Readonly<PermissionsBitField> | null;
lockPermissions(): Promise<this>;
}
/**
* Text channel in a guild
* @extends BaseGuildTextChannel
*/
class TextChannel extends BaseGuildTextChannel {
readonly type: ChannelType.GuildText;
readonly threads: GuildTextThreadManager;
setTopic(topic: string | null, reason?: string): Promise<this>;
setNSFW(nsfw?: boolean, reason?: string): Promise<this>;
setRateLimitPerUser(rateLimitPerUser: number, reason?: string): Promise<this>;
setDefaultAutoArchiveDuration(defaultAutoArchiveDuration: ThreadAutoArchiveDuration | null, reason?: string): Promise<this>;
}
/**
* Voice channel in a guild
* @extends BaseGuildVoiceChannel
*/
class VoiceChannel extends BaseGuildVoiceChannel {
readonly type: ChannelType.GuildVoice;
readonly bitrate: number;
readonly userLimit: number;
readonly rtcRegion: string | null;
readonly videoQualityMode: VideoQualityMode | null;
setBitrate(bitrate: number, reason?: string): Promise<this>;
setUserLimit(userLimit: number, reason?: string): Promise<this>;
setRTCRegion(rtcRegion: string | null, reason?: string): Promise<this>;
setVideoQualityMode(videoQualityMode: VideoQualityMode | null, reason?: string): Promise<this>;
}
/**
* Category channel for organizing other channels
* @extends GuildChannel
*/
class CategoryChannel extends GuildChannel {
readonly type: ChannelType.GuildCategory;
readonly children: CategoryChildChannel[];
}
/**
* Forum channel for threaded discussions
* @extends GuildChannel
*/
class ForumChannel extends GuildChannel {
readonly type: ChannelType.GuildForum;
readonly threads: GuildForumThreadManager;
readonly availableTags: GuildForumTag[];
readonly defaultReactionEmoji: DefaultReactionEmoji | null;
readonly defaultThreadRateLimitPerUser: number | null;
readonly rateLimitPerUser: number;
readonly defaultSortOrder: SortOrderType | null;
readonly defaultForumLayout: ForumLayoutType;
setAvailableTags(availableTags: GuildForumTagData[], reason?: string): Promise<this>;
setTopic(topic: string | null, reason?: string): Promise<this>;
setDefaultReactionEmoji(defaultReactionEmoji: DefaultReactionEmoji | null, reason?: string): Promise<this>;
}/**
* Represents permission overwrites for a channel
*/
class PermissionOverwrites extends Base {
readonly id: Snowflake;
readonly type: OverwriteType;
readonly deny: Readonly<PermissionsBitField>;
readonly allow: Readonly<PermissionsBitField>;
edit(options: PermissionOverwriteOptions, reason?: string): Promise<PermissionOverwrites>;
delete(reason?: string): Promise<PermissionOverwrites>;
}
/**
* BitField representing Discord permissions
*/
class PermissionsBitField extends BitField<PermissionsString> {
static Flags: typeof PermissionFlagsBits;
static All: bigint;
static Default: bigint;
static StageModerator: bigint;
any(permission: PermissionResolvable, checkAdmin?: boolean): boolean;
has(permission: PermissionResolvable, checkAdmin?: boolean): boolean;
missing(permissions: PermissionResolvable, checkAdmin?: boolean): PermissionsString[];
serialize(checkAdmin?: boolean): Record<PermissionsString, boolean>;
toArray(): PermissionsString[];
}
const PermissionFlagsBits: {
CreateInstantInvite: 1n << 0n;
KickMembers: 1n << 1n;
BanMembers: 1n << 2n;
Administrator: 1n << 3n;
ManageChannels: 1n << 4n;
ManageGuild: 1n << 5n;
AddReactions: 1n << 6n;
ViewAuditLog: 1n << 7n;
PrioritySpeaker: 1n << 8n;
Stream: 1n << 9n;
ViewChannel: 1n << 10n;
SendMessages: 1n << 11n;
SendTTSMessages: 1n << 12n;
ManageMessages: 1n << 13n;
EmbedLinks: 1n << 14n;
AttachFiles: 1n << 15n;
ReadMessageHistory: 1n << 16n;
MentionEveryone: 1n << 17n;
UseExternalEmojis: 1n << 18n;
ViewGuildInsights: 1n << 19n;
Connect: 1n << 20n;
Speak: 1n << 21n;
MuteMembers: 1n << 22n;
DeafenMembers: 1n << 23n;
MoveMembers: 1n << 24n;
UseVAD: 1n << 25n;
ChangeNickname: 1n << 26n;
ManageNicknames: 1n << 27n;
ManageRoles: 1n << 28n;
ManageWebhooks: 1n << 29n;
ManageGuildExpressions: 1n << 30n;
UseApplicationCommands: 1n << 31n;
RequestToSpeak: 1n << 32n;
ManageEvents: 1n << 33n;
ManageThreads: 1n << 34n;
CreatePublicThreads: 1n << 35n;
CreatePrivateThreads: 1n << 36n;
UseExternalStickers: 1n << 37n;
SendMessagesInThreads: 1n << 38n;
UseEmbeddedActivities: 1n << 39n;
ModerateMembers: 1n << 40n;
ViewCreatorMonetizationAnalytics: 1n << 41n;
UseSoundboard: 1n << 42n;
UseExternalSounds: 1n << 45n;
SendVoiceMessages: 1n << 46n;
};/**
* Manages guild channels
*/
class GuildChannelManager extends CachedManager<Snowflake, GuildChannel, GuildChannelResolvable> {
create(options: GuildChannelCreateOptions): Promise<GuildChannel>;
edit(channel: GuildChannelResolvable, options: GuildChannelEditOptions): Promise<GuildChannel>;
delete(channel: GuildChannelResolvable, reason?: string): Promise<void>;
setPosition(channel: GuildChannelResolvable, position: number, options?: SetChannelPositionOptions): Promise<GuildChannel>;
setPositions(channelPositions: readonly ChannelPosition[]): Promise<Guild>;
fetchActiveThreads(cache?: boolean): Promise<FetchedThreads>;
}
/**
* Manages guild members
*/
class GuildMemberManager extends CachedManager<Snowflake, GuildMember, GuildMemberResolvable> {
add(user: UserResolvable, options: AddGuildMemberOptions): Promise<GuildMember>;
ban(user: UserResolvable, options?: BanOptions): Promise<GuildMember | User | Snowflake>;
edit(user: UserResolvable, options: GuildMemberEditOptions): Promise<GuildMember>;
kick(user: UserResolvable, reason?: string): Promise<GuildMember | User | Snowflake>;
list(options?: GuildListMembersOptions): Promise<Collection<Snowflake, GuildMember>>;
prune(options?: GuildPruneMembersOptions): Promise<number | null>;
search(options: GuildSearchMembersOptions): Promise<Collection<Snowflake, GuildMember>>;
unban(user: UserResolvable, reason?: string): Promise<User | null>;
}
/**
* Manages guild roles
*/
class RoleManager extends CachedManager<Snowflake, Role, RoleResolvable> {
create(options?: CreateRoleOptions): Promise<Role>;
edit(role: RoleResolvable, options: RoleEditOptions): Promise<Role>;
delete(role: RoleResolvable, reason?: string): Promise<void>;
setPosition(role: RoleResolvable, position: number, reason?: string): Promise<Role>;
setPositions(rolePositions: readonly RolePosition[]): Promise<Guild>;
readonly everyone: Role;
readonly premiumSubscriberRole: Role | null;
readonly botRoleFor: (user: UserResolvable) => Role | null;
comparePositions(role1: RoleResolvable, role2: RoleResolvable): number;
}Usage Examples:
// Create a new role
const moderatorRole = await guild.roles.create({
name: 'Moderator',
color: Colors.Blue,
permissions: [PermissionFlagsBits.KickMembers, PermissionFlagsBits.ManageMessages],
hoist: true,
mentionable: true,
reason: 'Created moderator role'
});
// Add role to member
const member = await guild.members.fetch('123456789012345678');
await member.roles.add(moderatorRole, 'Promoted to moderator');
// Create text channel with permissions
const channel = await guild.channels.create({
name: 'staff-only',
type: ChannelType.GuildText,
permissionOverwrites: [
{
id: guild.roles.everyone.id,
deny: [PermissionFlagsBits.ViewChannel]
},
{
id: moderatorRole.id,
allow: [PermissionFlagsBits.ViewChannel, PermissionFlagsBits.SendMessages]
}
]
});
// Ban a member
await guild.members.ban('123456789012345678', {
deleteMessageSeconds: 7 * 24 * 60 * 60, // 7 days
reason: 'Violating server rules'
});
// Check member permissions
const memberPermissions = member.permissions;
if (memberPermissions.has(PermissionFlagsBits.Administrator)) {
console.log('Member has administrator permissions');
}
// Check channel-specific permissions
const channelPermissions = member.permissionsIn(channel);
if (channelPermissions.has(PermissionFlagsBits.SendMessages)) {
console.log('Member can send messages in this channel');
}Install with Tessl CLI
npx tessl i tessl/npm-discord-js