refactor: Make constants enums top level and PascalCase (#7379)

Co-authored-by: Vitor <milagre.vitor@gmail.com>
Co-authored-by: almeidx <almeidx@pm.me>
This commit is contained in:
Suneet Tipirneni
2022-02-05 13:56:11 -05:00
committed by GitHub
parent cd2f566052
commit d8184f94dd
81 changed files with 623 additions and 638 deletions

View File

@@ -22,11 +22,13 @@ const StickerPack = require('../structures/StickerPack');
const VoiceRegion = require('../structures/VoiceRegion');
const Webhook = require('../structures/Webhook');
const Widget = require('../structures/Widget');
const { Events, InviteScopes, Status } = require('../util/Constants');
const { InviteScopes } = require('../util/Constants');
const DataResolver = require('../util/DataResolver');
const Events = require('../util/Events');
const IntentsBitField = require('../util/IntentsBitField');
const Options = require('../util/Options');
const PermissionsBitField = require('../util/PermissionsBitField');
const Status = require('../util/Status');
const Sweepers = require('../util/Sweepers');
/**
@@ -213,7 +215,7 @@ class Client extends BaseClient {
this.token = token = token.replace(/^(Bot|Bearer)\s*/i, '');
this.rest.setToken(token);
this.emit(
Events.DEBUG,
Events.Debug,
`Provided token: ${token
.split('.')
.map((val, i) => (i > 1 ? val.replace(/./g, '*') : val))
@@ -224,7 +226,7 @@ class Client extends BaseClient {
this.options.ws.presence = this.presence._parse(this.options.presence);
}
this.emit(Events.DEBUG, 'Preparing to connect to the gateway...');
this.emit(Events.Debug, 'Preparing to connect to the gateway...');
try {
await this.ws.connect();
@@ -241,7 +243,7 @@ class Client extends BaseClient {
* @returns {boolean}
*/
isReady() {
return this.ws.status === Status.READY;
return this.ws.status === Status.Ready;
}
/**

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class ChannelCreateAction extends Action {
handle(data) {
@@ -14,7 +14,7 @@ class ChannelCreateAction extends Action {
* @event Client#channelCreate
* @param {GuildChannel} channel The channel that was created
*/
client.emit(Events.CHANNEL_CREATE, channel);
client.emit(Events.ChannelCreate, channel);
}
return { channel };
}

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class ChannelDeleteAction extends Action {
handle(data) {
@@ -15,7 +15,7 @@ class ChannelDeleteAction extends Action {
* @event Client#channelDelete
* @param {DMChannel|GuildChannel} channel The channel that was deleted
*/
client.emit(Events.CHANNEL_DELETE, channel);
client.emit(Events.ChannelDelete, channel);
}
}
}

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class GuildBanAdd extends Action {
handle(data) {
@@ -13,7 +13,7 @@ class GuildBanAdd extends Action {
* @event Client#guildBanAdd
* @param {GuildBan} ban The ban that occurred
*/
if (guild) client.emit(Events.GUILD_BAN_ADD, guild.bans._add(data));
if (guild) client.emit(Events.GuildBanAdd, guild.bans._add(data));
}
}

View File

@@ -2,7 +2,7 @@
const Action = require('./Action');
const GuildBan = require('../../structures/GuildBan');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class GuildBanRemove extends Action {
handle(data) {
@@ -17,7 +17,7 @@ class GuildBanRemove extends Action {
if (guild) {
const ban = guild.bans.cache.get(data.user.id) ?? new GuildBan(client, data, guild);
guild.bans.cache.delete(ban.user.id);
client.emit(Events.GUILD_BAN_REMOVE, ban);
client.emit(Events.GuildBanRemove, ban);
}
}
}

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class GuildDeleteAction extends Action {
handle(data) {
@@ -18,7 +18,7 @@ class GuildDeleteAction extends Action {
* @event Client#guildUnavailable
* @param {Guild} guild The guild that has become unavailable
*/
client.emit(Events.GUILD_UNAVAILABLE, guild);
client.emit(Events.GuildUnavailable, guild);
// Stops the GuildDelete packet thinking a guild was actually deleted,
// handles emitting of event itself
@@ -36,7 +36,7 @@ class GuildDeleteAction extends Action {
* @event Client#guildDelete
* @param {Guild} guild The guild that was deleted
*/
client.emit(Events.GUILD_DELETE, guild);
client.emit(Events.GuildDelete, guild);
}
}
}

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class GuildEmojiCreateAction extends Action {
handle(guild, createdEmoji) {
@@ -12,7 +12,7 @@ class GuildEmojiCreateAction extends Action {
* @event Client#emojiCreate
* @param {GuildEmoji} emoji The emoji that was created
*/
if (!already) this.client.emit(Events.GUILD_EMOJI_CREATE, emoji);
if (!already) this.client.emit(Events.GuildEmojiCreate, emoji);
return { emoji };
}
}

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class GuildEmojiDeleteAction extends Action {
handle(emoji) {
@@ -11,7 +11,7 @@ class GuildEmojiDeleteAction extends Action {
* @event Client#emojiDelete
* @param {GuildEmoji} emoji The emoji that was deleted
*/
this.client.emit(Events.GUILD_EMOJI_DELETE, emoji);
this.client.emit(Events.GuildEmojiDelete, emoji);
return { emoji };
}
}

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class GuildEmojiUpdateAction extends Action {
handle(current, data) {
@@ -12,7 +12,7 @@ class GuildEmojiUpdateAction extends Action {
* @param {GuildEmoji} oldEmoji The old emoji
* @param {GuildEmoji} newEmoji The new emoji
*/
this.client.emit(Events.GUILD_EMOJI_UPDATE, old, current);
this.client.emit(Events.GuildEmojiUpdate, old, current);
return { emoji: current };
}
}

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class GuildIntegrationsUpdate extends Action {
handle(data) {
@@ -12,7 +12,7 @@ class GuildIntegrationsUpdate extends Action {
* @event Client#guildIntegrationsUpdate
* @param {Guild} guild The guild whose integrations were updated
*/
if (guild) client.emit(Events.GUILD_INTEGRATIONS_UPDATE, guild);
if (guild) client.emit(Events.GuildIntegrationsUpdate, guild);
}
}

View File

@@ -1,7 +1,8 @@
'use strict';
const Action = require('./Action');
const { Events, Status } = require('../../util/Constants');
const Events = require('../../util/Events');
const Status = require('../../util/Status');
class GuildMemberRemoveAction extends Action {
handle(data, shard) {
@@ -18,7 +19,7 @@ class GuildMemberRemoveAction extends Action {
* @event Client#guildMemberRemove
* @param {GuildMember} member The member that has left/been kicked from the guild
*/
if (shard.status === Status.READY) client.emit(Events.GUILD_MEMBER_REMOVE, member);
if (shard.status === Status.Ready) client.emit(Events.GuildMemberRemove, member);
}
guild.voiceStates.cache.delete(data.user.id);
}

View File

@@ -1,7 +1,8 @@
'use strict';
const Action = require('./Action');
const { Status, Events } = require('../../util/Constants');
const Events = require('../../util/Events');
const Status = require('../../util/Status');
class GuildMemberUpdateAction extends Action {
handle(data, shard) {
@@ -26,7 +27,7 @@ class GuildMemberUpdateAction extends Action {
* @param {GuildMember} oldMember The member before the update
* @param {GuildMember} newMember The member after the update
*/
if (shard.status === Status.READY && !member.equals(old)) client.emit(Events.GUILD_MEMBER_UPDATE, old, member);
if (shard.status === Status.Ready && !member.equals(old)) client.emit(Events.GuildMemberUpdate, old, member);
} else {
const newMember = guild.members._add(data);
/**
@@ -34,7 +35,7 @@ class GuildMemberUpdateAction extends Action {
* @event Client#guildMemberAvailable
* @param {GuildMember} member The member that became available
*/
this.client.emit(Events.GUILD_MEMBER_AVAILABLE, newMember);
this.client.emit(Events.GuildMemberAvailable, newMember);
}
}
}

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class GuildRoleCreate extends Action {
handle(data) {
@@ -16,7 +16,7 @@ class GuildRoleCreate extends Action {
* @event Client#roleCreate
* @param {Role} role The role that was created
*/
if (!already) client.emit(Events.GUILD_ROLE_CREATE, role);
if (!already) client.emit(Events.GuildRoleCreate, role);
}
return { role };
}

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class GuildRoleDeleteAction extends Action {
handle(data) {
@@ -18,7 +18,7 @@ class GuildRoleDeleteAction extends Action {
* @event Client#roleDelete
* @param {Role} role The role that was deleted
*/
client.emit(Events.GUILD_ROLE_DELETE, role);
client.emit(Events.GuildRoleDelete, role);
}
}

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class GuildRoleUpdateAction extends Action {
handle(data) {
@@ -20,7 +20,7 @@ class GuildRoleUpdateAction extends Action {
* @param {Role} oldRole The role before the update
* @param {Role} newRole The role after the update
*/
client.emit(Events.GUILD_ROLE_UPDATE, old, role);
client.emit(Events.GuildRoleUpdate, old, role);
}
return {

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class GuildScheduledEventCreateAction extends Action {
handle(data) {
@@ -15,7 +15,7 @@ class GuildScheduledEventCreateAction extends Action {
* @event Client#guildScheduledEventCreate
* @param {GuildScheduledEvent} guildScheduledEvent The created guild scheduled event
*/
client.emit(Events.GUILD_SCHEDULED_EVENT_CREATE, guildScheduledEvent);
client.emit(Events.GuildScheduledEventCreate, guildScheduledEvent);
return { guildScheduledEvent };
}

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class GuildScheduledEventDeleteAction extends Action {
handle(data) {
@@ -18,7 +18,7 @@ class GuildScheduledEventDeleteAction extends Action {
* @event Client#guildScheduledEventDelete
* @param {GuildScheduledEvent} guildScheduledEvent The deleted guild scheduled event
*/
client.emit(Events.GUILD_SCHEDULED_EVENT_DELETE, guildScheduledEvent);
client.emit(Events.GuildScheduledEventDelete, guildScheduledEvent);
return { guildScheduledEvent };
}

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class GuildScheduledEventUpdateAction extends Action {
handle(data) {
@@ -18,7 +18,7 @@ class GuildScheduledEventUpdateAction extends Action {
* @param {?GuildScheduledEvent} oldGuildScheduledEvent The guild scheduled event object before the update
* @param {GuildScheduledEvent} newGuildScheduledEvent The guild scheduled event object after the update
*/
client.emit(Events.GUILD_SCHEDULED_EVENT_UPDATE, oldGuildScheduledEvent, newGuildScheduledEvent);
client.emit(Events.GuildScheduledEventUpdate, oldGuildScheduledEvent, newGuildScheduledEvent);
return { oldGuildScheduledEvent, newGuildScheduledEvent };
}

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class GuildScheduledEventUserAddAction extends Action {
handle(data) {
@@ -19,7 +19,7 @@ class GuildScheduledEventUserAddAction extends Action {
* @param {GuildScheduledEvent} guildScheduledEvent The guild scheduled event
* @param {User} user The user who subscribed
*/
client.emit(Events.GUILD_SCHEDULED_EVENT_USER_ADD, guildScheduledEvent, user);
client.emit(Events.GuildScheduledEventUserAdd, guildScheduledEvent, user);
return { guildScheduledEvent, user };
}

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class GuildScheduledEventUserRemoveAction extends Action {
handle(data) {
@@ -19,7 +19,7 @@ class GuildScheduledEventUserRemoveAction extends Action {
* @param {GuildScheduledEvent} guildScheduledEvent The guild scheduled event
* @param {User} user The user who unsubscribed
*/
client.emit(Events.GUILD_SCHEDULED_EVENT_USER_REMOVE, guildScheduledEvent, user);
client.emit(Events.GuildScheduledEventUserRemove, guildScheduledEvent, user);
return { guildScheduledEvent, user };
}

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class GuildStickerCreateAction extends Action {
handle(guild, createdSticker) {
@@ -12,7 +12,7 @@ class GuildStickerCreateAction extends Action {
* @event Client#stickerCreate
* @param {Sticker} sticker The sticker that was created
*/
if (!already) this.client.emit(Events.GUILD_STICKER_CREATE, sticker);
if (!already) this.client.emit(Events.GuildStickerCreate, sticker);
return { sticker };
}
}

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class GuildStickerDeleteAction extends Action {
handle(sticker) {
@@ -11,7 +11,7 @@ class GuildStickerDeleteAction extends Action {
* @event Client#stickerDelete
* @param {Sticker} sticker The sticker that was deleted
*/
this.client.emit(Events.GUILD_STICKER_DELETE, sticker);
this.client.emit(Events.GuildStickerDelete, sticker);
return { sticker };
}
}

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class GuildStickerUpdateAction extends Action {
handle(current, data) {
@@ -12,7 +12,7 @@ class GuildStickerUpdateAction extends Action {
* @param {Sticker} oldSticker The old sticker
* @param {Sticker} newSticker The new sticker
*/
this.client.emit(Events.GUILD_STICKER_UPDATE, old, current);
this.client.emit(Events.GuildStickerUpdate, old, current);
return { sticker: current };
}
}

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class GuildUpdateAction extends Action {
handle(data) {
@@ -16,7 +16,7 @@ class GuildUpdateAction extends Action {
* @param {Guild} oldGuild The guild before the update
* @param {Guild} newGuild The guild after the update
*/
client.emit(Events.GUILD_UPDATE, old, guild);
client.emit(Events.GuildUpdate, old, guild);
return {
old,
updated: guild,

View File

@@ -8,7 +8,7 @@ const ChatInputCommandInteraction = require('../../structures/ChatInputCommandIn
const MessageContextMenuCommandInteraction = require('../../structures/MessageContextMenuCommandInteraction');
const SelectMenuInteraction = require('../../structures/SelectMenuInteraction');
const UserContextMenuCommandInteraction = require('../../structures/UserContextMenuCommandInteraction');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class InteractionCreateAction extends Action {
handle(data) {
@@ -32,7 +32,7 @@ class InteractionCreateAction extends Action {
break;
default:
client.emit(
Events.DEBUG,
Events.Debug,
`[INTERACTION] Received application command interaction with unknown type: ${data.data.type}`,
);
return;
@@ -48,7 +48,7 @@ class InteractionCreateAction extends Action {
break;
default:
client.emit(
Events.DEBUG,
Events.Debug,
`[INTERACTION] Received component interaction with unknown type: ${data.data.component_type}`,
);
return;
@@ -58,7 +58,7 @@ class InteractionCreateAction extends Action {
InteractionClass = AutocompleteInteraction;
break;
default:
client.emit(Events.DEBUG, `[INTERACTION] Received interaction with unknown type: ${data.type}`);
client.emit(Events.Debug, `[INTERACTION] Received interaction with unknown type: ${data.type}`);
return;
}
@@ -69,7 +69,7 @@ class InteractionCreateAction extends Action {
* @event Client#interactionCreate
* @param {Interaction} interaction The interaction which was created
*/
client.emit(Events.INTERACTION_CREATE, interaction);
client.emit(Events.InteractionCreate, interaction);
}
}

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class InviteCreateAction extends Action {
handle(data) {
@@ -20,7 +20,7 @@ class InviteCreateAction extends Action {
* @event Client#inviteCreate
* @param {Invite} invite The invite that was created
*/
client.emit(Events.INVITE_CREATE, invite);
client.emit(Events.InviteCreate, invite);
return { invite };
}
}

View File

@@ -2,7 +2,7 @@
const Action = require('./Action');
const Invite = require('../../structures/Invite');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class InviteDeleteAction extends Action {
handle(data) {
@@ -22,7 +22,7 @@ class InviteDeleteAction extends Action {
* @event Client#inviteDelete
* @param {Invite} invite The invite that was deleted
*/
client.emit(Events.INVITE_DELETE, invite);
client.emit(Events.InviteDelete, invite);
return { invite };
}
}

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class MessageCreateAction extends Action {
handle(data) {
@@ -20,7 +20,7 @@ class MessageCreateAction extends Action {
* @event Client#messageCreate
* @param {Message} message The created message
*/
client.emit(Events.MESSAGE_CREATE, message);
client.emit(Events.MessageCreate, message);
return { message };
}

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class MessageDeleteAction extends Action {
handle(data) {
@@ -19,7 +19,7 @@ class MessageDeleteAction extends Action {
* @event Client#messageDelete
* @param {Message} message The deleted message
*/
client.emit(Events.MESSAGE_DELETE, message);
client.emit(Events.MessageDelete, message);
}
}

View File

@@ -2,7 +2,7 @@
const { Collection } = require('@discordjs/collection');
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class MessageDeleteBulkAction extends Action {
handle(data) {
@@ -34,7 +34,7 @@ class MessageDeleteBulkAction extends Action {
* @event Client#messageDeleteBulk
* @param {Collection<Snowflake, Message>} messages The deleted messages, mapped by their id
*/
if (messages.size > 0) client.emit(Events.MESSAGE_BULK_DELETE, messages);
if (messages.size > 0) client.emit(Events.MessageBulkDelete, messages);
return { messages };
}
return {};

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
const Partials = require('../../util/Partials');
/*
@@ -46,7 +46,7 @@ class MessageReactionAdd extends Action {
* @param {MessageReaction} messageReaction The reaction object
* @param {User} user The user that applied the guild or reaction emoji
*/
this.client.emit(Events.MESSAGE_REACTION_ADD, reaction, user);
this.client.emit(Events.MessageReactionAdd, reaction, user);
return { message, reaction, user };
}

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
/*
{ user_id: 'id',
@@ -36,7 +36,7 @@ class MessageReactionRemove extends Action {
* @param {MessageReaction} messageReaction The reaction object
* @param {User} user The user whose emoji or reaction emoji was removed
*/
this.client.emit(Events.MESSAGE_REACTION_REMOVE, reaction, user);
this.client.emit(Events.MessageReactionRemove, reaction, user);
return { message, reaction, user };
}

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class MessageReactionRemoveAll extends Action {
handle(data) {
@@ -17,7 +17,7 @@ class MessageReactionRemoveAll extends Action {
const removed = message.reactions.cache.clone();
message.reactions.cache.clear();
this.client.emit(Events.MESSAGE_REACTION_REMOVE_ALL, message, removed);
this.client.emit(Events.MessageReactionRemoveAll, message, removed);
return { message };
}

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class MessageReactionRemoveEmoji extends Action {
handle(data) {
@@ -20,7 +20,7 @@ class MessageReactionRemoveEmoji extends Action {
* @event Client#messageReactionRemoveEmoji
* @param {MessageReaction} reaction The reaction that was removed
*/
this.client.emit(Events.MESSAGE_REACTION_REMOVE_EMOJI, reaction);
this.client.emit(Events.MessageReactionRemoveEmoji, reaction);
return { reaction };
}
}

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class PresenceUpdateAction extends Action {
handle(data) {
@@ -24,17 +24,17 @@ class PresenceUpdateAction extends Action {
deaf: false,
mute: false,
});
this.client.emit(Events.GUILD_MEMBER_AVAILABLE, member);
this.client.emit(Events.GuildMemberAvailable, member);
}
const newPresence = guild.presences._add(Object.assign(data, { guild }));
if (this.client.listenerCount(Events.PRESENCE_UPDATE) && !newPresence.equals(oldPresence)) {
if (this.client.listenerCount(Events.PresenceUpdate) && !newPresence.equals(oldPresence)) {
/**
* Emitted whenever a guild member's presence (e.g. status, activity) is changed.
* @event Client#presenceUpdate
* @param {?Presence} oldPresence The presence before the update, if one at all
* @param {Presence} newPresence The presence after the update
*/
this.client.emit(Events.PRESENCE_UPDATE, oldPresence, newPresence);
this.client.emit(Events.PresenceUpdate, oldPresence, newPresence);
}
}
}

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class StageInstanceCreateAction extends Action {
handle(data) {
@@ -16,7 +16,7 @@ class StageInstanceCreateAction extends Action {
* @event Client#stageInstanceCreate
* @param {StageInstance} stageInstance The created stage instance
*/
client.emit(Events.STAGE_INSTANCE_CREATE, stageInstance);
client.emit(Events.StageInstanceCreate, stageInstance);
return { stageInstance };
}

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class StageInstanceDeleteAction extends Action {
handle(data) {
@@ -18,7 +18,7 @@ class StageInstanceDeleteAction extends Action {
* @event Client#stageInstanceDelete
* @param {StageInstance} stageInstance The deleted stage instance
*/
client.emit(Events.STAGE_INSTANCE_DELETE, stageInstance);
client.emit(Events.StageInstanceDelete, stageInstance);
return { stageInstance };
}

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class StageInstanceUpdateAction extends Action {
handle(data) {
@@ -18,7 +18,7 @@ class StageInstanceUpdateAction extends Action {
* @param {?StageInstance} oldStageInstance The stage instance before the update
* @param {StageInstance} newStageInstance The stage instance after the update
*/
client.emit(Events.STAGE_INSTANCE_UPDATE, oldStageInstance, newStageInstance);
client.emit(Events.StageInstanceUpdate, oldStageInstance, newStageInstance);
return { oldStageInstance, newStageInstance };
}

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class ThreadCreateAction extends Action {
handle(data) {
@@ -15,7 +15,7 @@ class ThreadCreateAction extends Action {
* @param {ThreadChannel} thread The thread that was created
* @param {boolean} newlyCreated Whether the thread was newly created
*/
client.emit(Events.THREAD_CREATE, thread, data.newly_created ?? false);
client.emit(Events.ThreadCreate, thread, data.newly_created ?? false);
}
return { thread };
}

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class ThreadDeleteAction extends Action {
handle(data) {
@@ -16,7 +16,7 @@ class ThreadDeleteAction extends Action {
* @event Client#threadDelete
* @param {ThreadChannel} thread The thread that was deleted
*/
client.emit(Events.THREAD_DELETE, thread);
client.emit(Events.ThreadDelete, thread);
}
return { thread };

View File

@@ -2,7 +2,7 @@
const { Collection } = require('@discordjs/collection');
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class ThreadListSyncAction extends Action {
handle(data) {
@@ -40,7 +40,7 @@ class ThreadListSyncAction extends Action {
* @event Client#threadListSync
* @param {Collection<Snowflake, ThreadChannel>} threads The threads that were synced
*/
client.emit(Events.THREAD_LIST_SYNC, syncedThreads);
client.emit(Events.ThreadListSync, syncedThreads);
return {
syncedThreads,

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class ThreadMemberUpdateAction extends Action {
handle(data) {
@@ -21,7 +21,7 @@ class ThreadMemberUpdateAction extends Action {
* @param {ThreadMember} oldMember The member before the update
* @param {ThreadMember} newMember The member after the update
*/
client.emit(Events.THREAD_MEMBER_UPDATE, old, member);
client.emit(Events.ThreadMemberUpdate, old, member);
}
return {};
}

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class ThreadMembersUpdateAction extends Action {
handle(data) {
@@ -25,7 +25,7 @@ class ThreadMembersUpdateAction extends Action {
* @param {Collection<Snowflake, ThreadMember>} oldMembers The members before the update
* @param {Collection<Snowflake, ThreadMember>} newMembers The members after the update
*/
client.emit(Events.THREAD_MEMBERS_UPDATE, old, thread.members.cache);
client.emit(Events.ThreadMembersUpdate, old, thread.members.cache);
}
return {};
}

View File

@@ -2,7 +2,7 @@
const Action = require('./Action');
const Typing = require('../../structures/Typing');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class TypingStart extends Action {
handle(data) {
@@ -10,7 +10,7 @@ class TypingStart extends Action {
if (!channel) return;
if (!channel.isTextBased()) {
this.client.emit(Events.WARN, `Discord sent a typing packet to a ${channel.type} channel ${channel.id}`);
this.client.emit(Events.Warn, `Discord sent a typing packet to a ${channel.type} channel ${channel.id}`);
return;
}
@@ -21,7 +21,7 @@ class TypingStart extends Action {
* @event Client#typingStart
* @param {Typing} typing The typing state
*/
this.client.emit(Events.TYPING_START, new Typing(channel, user, data));
this.client.emit(Events.TypingStart, new Typing(channel, user, data));
}
}
}

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class UserUpdateAction extends Action {
handle(data) {
@@ -18,7 +18,7 @@ class UserUpdateAction extends Action {
* @param {User} oldUser The user before the update
* @param {User} newUser The user after the update
*/
client.emit(Events.USER_UPDATE, oldUser, newUser);
client.emit(Events.UserUpdate, oldUser, newUser);
return {
old: oldUser,
updated: newUser,

View File

@@ -2,7 +2,7 @@
const Action = require('./Action');
const VoiceState = require('../../structures/VoiceState');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class VoiceStateUpdate extends Action {
handle(data) {
@@ -35,7 +35,7 @@ class VoiceStateUpdate extends Action {
* @param {VoiceState} oldState The voice state before the update
* @param {VoiceState} newState The voice state after the update
*/
client.emit(Events.VOICE_STATE_UPDATE, oldState, newState);
client.emit(Events.VoiceStateUpdate, oldState, newState);
}
}
}

View File

@@ -1,7 +1,7 @@
'use strict';
const Action = require('./Action');
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
class WebhooksUpdate extends Action {
handle(data) {
@@ -12,7 +12,7 @@ class WebhooksUpdate extends Action {
* @event Client#webhookUpdate
* @param {TextChannel|NewsChannel} channel The channel that had a webhook update
*/
if (channel) client.emit(Events.WEBHOOKS_UPDATE, channel);
if (channel) client.emit(Events.WebhooksUpdate, channel);
}
}

View File

@@ -1,6 +1,6 @@
'use strict';
const { Events } = require('../../util/Constants');
const Events = require('../../util/Events');
/**
* Manages voice connections for the client
@@ -21,7 +21,7 @@ class ClientVoiceManager {
*/
this.adapters = new Map();
client.on(Events.SHARD_DISCONNECT, (_, shardId) => {
client.on(Events.ShardDisconnect, (_, shardId) => {
for (const [guildId, adapter] of this.adapters.entries()) {
if (client.guilds.cache.get(guildId)?.shardId === shardId) {
adapter.destroy();

View File

@@ -8,7 +8,10 @@ const { Routes, RPCErrorCodes } = require('discord-api-types/v9');
const WebSocketShard = require('./WebSocketShard');
const PacketHandlers = require('./handlers');
const { Error } = require('../../errors');
const { Events, ShardEvents, Status, WSCodes, WSEvents } = require('../../util/Constants');
const { WSCodes, WSEvents } = require('../../util/Constants');
const Events = require('../../util/Events');
const ShardEvents = require('../../util/ShardEvents');
const Status = require('../../util/Status');
const BeforeReadyWhitelist = [
WSEvents.READY,
@@ -84,7 +87,7 @@ class WebSocketManager extends EventEmitter {
* The current status of this WebSocketManager
* @type {Status}
*/
this.status = Status.IDLE;
this.status = Status.Idle;
/**
* If this manager was destroyed. It will prevent shards from reconnecting
@@ -118,7 +121,7 @@ class WebSocketManager extends EventEmitter {
* @private
*/
debug(message, shard) {
this.client.emit(Events.DEBUG, `[WS => ${shard ? `Shard ${shard.id}` : 'Manager'}] ${message}`);
this.client.emit(Events.Debug, `[WS => ${shard ? `Shard ${shard.id}` : 'Manager'}] ${message}`);
}
/**
@@ -176,20 +179,20 @@ class WebSocketManager extends EventEmitter {
this.shardQueue.delete(shard);
if (!shard.eventsAttached) {
shard.on(ShardEvents.ALL_READY, unavailableGuilds => {
shard.on(ShardEvents.AllReady, unavailableGuilds => {
/**
* Emitted when a shard turns ready.
* @event Client#shardReady
* @param {number} id The shard id that turned ready
* @param {?Set<Snowflake>} unavailableGuilds Set of unavailable guild ids, if any
*/
this.client.emit(Events.SHARD_READY, shard.id, unavailableGuilds);
this.client.emit(Events.ShardReady, shard.id, unavailableGuilds);
if (!this.shardQueue.size) this.reconnecting = false;
this.checkShardsReady();
});
shard.on(ShardEvents.CLOSE, event => {
shard.on(ShardEvents.Close, event => {
if (event.code === 1_000 ? this.destroyed : UNRECOVERABLE_CLOSE_CODES.includes(event.code)) {
/**
* Emitted when a shard's WebSocket disconnects and will no longer reconnect.
@@ -197,7 +200,7 @@ class WebSocketManager extends EventEmitter {
* @param {CloseEvent} event The WebSocket close event
* @param {number} id The shard id that disconnected
*/
this.client.emit(Events.SHARD_DISCONNECT, event, shard.id);
this.client.emit(Events.ShardDisconnect, event, shard.id);
this.debug(WSCodes[event.code], shard);
return;
}
@@ -212,7 +215,7 @@ class WebSocketManager extends EventEmitter {
* @event Client#shardReconnecting
* @param {number} id The shard id that is attempting to reconnect
*/
this.client.emit(Events.SHARD_RECONNECTING, shard.id);
this.client.emit(Events.ShardReconnecting, shard.id);
this.shardQueue.add(shard);
@@ -225,14 +228,14 @@ class WebSocketManager extends EventEmitter {
}
});
shard.on(ShardEvents.INVALID_SESSION, () => {
this.client.emit(Events.SHARD_RECONNECTING, shard.id);
shard.on(ShardEvents.InvalidSession, () => {
this.client.emit(Events.ShardReconnecting, shard.id);
});
shard.on(ShardEvents.DESTROYED, () => {
shard.on(ShardEvents.Destroyed, () => {
this.debug('Shard was destroyed but no WebSocket connection was present! Reconnecting...', shard);
this.client.emit(Events.SHARD_RECONNECTING, shard.id);
this.client.emit(Events.ShardReconnecting, shard.id);
this.shardQueue.add(shard);
this.reconnect();
@@ -272,7 +275,7 @@ class WebSocketManager extends EventEmitter {
* @returns {Promise<boolean>}
*/
async reconnect() {
if (this.reconnecting || this.status !== Status.READY) return false;
if (this.reconnecting || this.status !== Status.Ready) return false;
this.reconnecting = true;
try {
await this.createShards();
@@ -285,14 +288,14 @@ class WebSocketManager extends EventEmitter {
return this.reconnect();
}
// If we get an error at this point, it means we cannot reconnect anymore
if (this.client.listenerCount(Events.INVALIDATED)) {
if (this.client.listenerCount(Events.Invalidated)) {
/**
* Emitted when the client's session becomes invalidated.
* You are expected to handle closing the process gracefully and preventing a boot loop
* if you are listening to this event.
* @event Client#invalidated
*/
this.client.emit(Events.INVALIDATED);
this.client.emit(Events.Invalidated);
// Destroy just the shards. This means you have to handle the cleanup yourself
this.destroy();
} else {
@@ -333,7 +336,7 @@ class WebSocketManager extends EventEmitter {
* @private
*/
handlePacket(packet, shard) {
if (packet && this.status !== Status.READY) {
if (packet && this.status !== Status.Ready) {
if (!BeforeReadyWhitelist.includes(packet.t)) {
this.packetQueue.push({ packet, shard });
return false;
@@ -359,8 +362,8 @@ class WebSocketManager extends EventEmitter {
* @private
*/
checkShardsReady() {
if (this.status === Status.READY) return;
if (this.shards.size !== this.totalShards || this.shards.some(s => s.status !== Status.READY)) {
if (this.status === Status.Ready) return;
if (this.shards.size !== this.totalShards || this.shards.some(s => s.status !== Status.Ready)) {
return;
}
@@ -372,7 +375,7 @@ class WebSocketManager extends EventEmitter {
* @private
*/
triggerClientReady() {
this.status = Status.READY;
this.status = Status.Ready;
this.client.readyTimestamp = Date.now();
@@ -381,7 +384,7 @@ class WebSocketManager extends EventEmitter {
* @event Client#ready
* @param {Client} client The client
*/
this.client.emit(Events.CLIENT_READY, this.client);
this.client.emit(Events.ClientReady, this.client);
this.handlePacket();
}

View File

@@ -2,10 +2,13 @@
const EventEmitter = require('node:events');
const { setTimeout, setInterval, clearTimeout, clearInterval } = require('node:timers');
const { GatewayIntentBits } = require('discord-api-types/v9');
const { GatewayIntentBits, GatewayOpcodes } = require('discord-api-types/v9');
const WebSocket = require('../../WebSocket');
const { Status, Events, ShardEvents, Opcodes, WSEvents } = require('../../util/Constants');
const { WSEvents } = require('../../util/Constants');
const Events = require('../../util/Events');
const IntentsBitField = require('../../util/IntentsBitField');
const ShardEvents = require('../../util/ShardEvents');
const Status = require('../../util/Status');
const STATUS_KEYS = Object.keys(Status);
const CONNECTION_STATE = Object.keys(WebSocket.WebSocket);
@@ -39,7 +42,7 @@ class WebSocketShard extends EventEmitter {
* The current status of the shard
* @type {Status}
*/
this.status = Status.IDLE;
this.status = Status.Idle;
/**
* The current sequence of the shard
@@ -178,17 +181,17 @@ class WebSocketShard extends EventEmitter {
connect() {
const { gateway, client } = this.manager;
if (this.connection?.readyState === WebSocket.OPEN && this.status === Status.READY) {
if (this.connection?.readyState === WebSocket.OPEN && this.status === Status.Ready) {
return Promise.resolve();
}
return new Promise((resolve, reject) => {
const cleanup = () => {
this.removeListener(ShardEvents.CLOSE, onClose);
this.removeListener(ShardEvents.READY, onReady);
this.removeListener(ShardEvents.RESUMED, onResumed);
this.removeListener(ShardEvents.INVALID_SESSION, onInvalidOrDestroyed);
this.removeListener(ShardEvents.DESTROYED, onInvalidOrDestroyed);
this.removeListener(ShardEvents.Close, onClose);
this.removeListener(ShardEvents.Ready, onReady);
this.removeListener(ShardEvents.Resumed, onResumed);
this.removeListener(ShardEvents.InvalidSession, onInvalidOrDestroyed);
this.removeListener(ShardEvents.Destroyed, onInvalidOrDestroyed);
};
const onReady = () => {
@@ -212,11 +215,11 @@ class WebSocketShard extends EventEmitter {
reject();
};
this.once(ShardEvents.READY, onReady);
this.once(ShardEvents.RESUMED, onResumed);
this.once(ShardEvents.CLOSE, onClose);
this.once(ShardEvents.INVALID_SESSION, onInvalidOrDestroyed);
this.once(ShardEvents.DESTROYED, onInvalidOrDestroyed);
this.once(ShardEvents.Ready, onReady);
this.once(ShardEvents.Resumed, onResumed);
this.once(ShardEvents.Close, onClose);
this.once(ShardEvents.InvalidSession, onInvalidOrDestroyed);
this.once(ShardEvents.Destroyed, onInvalidOrDestroyed);
if (this.connection?.readyState === WebSocket.OPEN) {
this.debug('An open connection was found, attempting an immediate identify.');
@@ -249,7 +252,7 @@ class WebSocketShard extends EventEmitter {
Compression: ${zlib ? 'zlib-stream' : 'none'}`,
);
this.status = this.status === Status.DISCONNECTED ? Status.RECONNECTING : Status.CONNECTING;
this.status = this.status === Status.Disconnected ? Status.Reconnecting : Status.Connecting;
this.setHelloTimeout();
this.connectedAt = Date.now();
@@ -268,7 +271,7 @@ class WebSocketShard extends EventEmitter {
*/
onOpen() {
this.debug(`[CONNECTED] Took ${Date.now() - this.connectedAt}ms`);
this.status = Status.NEARLY;
this.status = Status.Nearly;
}
/**
@@ -294,11 +297,11 @@ class WebSocketShard extends EventEmitter {
try {
packet = WebSocket.unpack(raw);
} catch (err) {
this.manager.client.emit(Events.SHARD_ERROR, err, this.id);
this.manager.client.emit(Events.ShardError, err, this.id);
return;
}
this.manager.client.emit(Events.RAW, packet, this.id);
if (packet.op === Opcodes.DISPATCH) this.manager.emit(packet.t, packet.d, this.id);
this.manager.client.emit(Events.Raw, packet, this.id);
if (packet.op === GatewayOpcodes.Dispatch) this.manager.emit(packet.t, packet.d, this.id);
this.onPacket(packet);
}
@@ -317,7 +320,7 @@ class WebSocketShard extends EventEmitter {
* @param {Error} error The encountered error
* @param {number} shardId The shard that encountered this error
*/
this.manager.client.emit(Events.SHARD_ERROR, error, this.id);
this.manager.client.emit(Events.ShardError, error, this.id);
}
/**
@@ -354,7 +357,7 @@ class WebSocketShard extends EventEmitter {
// If we still have a connection object, clean up its listeners
if (this.connection) this._cleanupConnection();
this.status = Status.DISCONNECTED;
this.status = Status.Disconnected;
/**
* Emitted when a shard's WebSocket closes.
@@ -362,7 +365,7 @@ class WebSocketShard extends EventEmitter {
* @event WebSocketShard#close
* @param {CloseEvent} event The received event
*/
this.emit(ShardEvents.CLOSE, event);
this.emit(ShardEvents.Close, event);
}
/**
@@ -382,11 +385,11 @@ class WebSocketShard extends EventEmitter {
* Emitted when the shard receives the READY payload and is now waiting for guilds
* @event WebSocketShard#ready
*/
this.emit(ShardEvents.READY);
this.emit(ShardEvents.Ready);
this.sessionId = packet.d.session_id;
this.expectedGuilds = new Set(packet.d.guilds.map(d => d.id));
this.status = Status.WAITING_FOR_GUILDS;
this.status = Status.WaitingForGuilds;
this.debug(`[READY] Session ${this.sessionId}.`);
this.lastHeartbeatAcked = true;
this.sendHeartbeat('ReadyHeartbeat');
@@ -396,9 +399,9 @@ class WebSocketShard extends EventEmitter {
* Emitted when the shard resumes successfully
* @event WebSocketShard#resumed
*/
this.emit(ShardEvents.RESUMED);
this.emit(ShardEvents.Resumed);
this.status = Status.READY;
this.status = Status.Ready;
const replayed = packet.s - this.closeSequence;
this.debug(`[RESUMED] Session ${this.sessionId} | Replayed ${replayed} events.`);
this.lastHeartbeatAcked = true;
@@ -410,16 +413,16 @@ class WebSocketShard extends EventEmitter {
if (packet.s > this.sequence) this.sequence = packet.s;
switch (packet.op) {
case Opcodes.HELLO:
case GatewayOpcodes.Hello:
this.setHelloTimeout(-1);
this.setHeartbeatTimer(packet.d.heartbeat_interval);
this.identify();
break;
case Opcodes.RECONNECT:
case GatewayOpcodes.Reconnect:
this.debug('[RECONNECT] Discord asked us to reconnect');
this.destroy({ closeCode: 4_000 });
break;
case Opcodes.INVALID_SESSION:
case GatewayOpcodes.InvalidSession:
this.debug(`[INVALID SESSION] Resumable: ${packet.d}.`);
// If we can resume the session, do so immediately
if (packet.d) {
@@ -431,19 +434,19 @@ class WebSocketShard extends EventEmitter {
// Reset the session id as it's invalid
this.sessionId = null;
// Set the status to reconnecting
this.status = Status.RECONNECTING;
this.status = Status.Reconnecting;
// Finally, emit the INVALID_SESSION event
this.emit(ShardEvents.INVALID_SESSION);
this.emit(ShardEvents.InvalidSession);
break;
case Opcodes.HEARTBEAT_ACK:
case GatewayOpcodes.HeartbeatAck:
this.ackHeartbeat();
break;
case Opcodes.HEARTBEAT:
case GatewayOpcodes.Heartbeat:
this.sendHeartbeat('HeartbeatRequest', true);
break;
default:
this.manager.handlePacket(packet, this);
if (this.status === Status.WAITING_FOR_GUILDS && packet.t === WSEvents.GUILD_CREATE) {
if (this.status === Status.WaitingForGuilds && packet.t === WSEvents.GUILD_CREATE) {
this.expectedGuilds.delete(packet.d.id);
this.checkReady();
}
@@ -463,7 +466,7 @@ class WebSocketShard extends EventEmitter {
// Step 1. If we don't have any other guilds pending, we are ready
if (!this.expectedGuilds.size) {
this.debug('Shard received all its guilds. Marking as fully ready.');
this.status = Status.READY;
this.status = Status.Ready;
/**
* Emitted when the shard is fully ready.
@@ -473,7 +476,7 @@ class WebSocketShard extends EventEmitter {
* @event WebSocketShard#allReady
* @param {?Set<string>} unavailableGuilds Set of unavailable guilds, if any
*/
this.emit(ShardEvents.ALL_READY);
this.emit(ShardEvents.AllReady);
return;
}
const hasGuildsIntent = new IntentsBitField(this.manager.client.options.intents).has(GatewayIntentBits.Guilds);
@@ -495,9 +498,9 @@ class WebSocketShard extends EventEmitter {
this.readyTimeout = null;
this.status = Status.READY;
this.status = Status.Ready;
this.emit(ShardEvents.ALL_READY, this.expectedGuilds);
this.emit(ShardEvents.AllReady, this.expectedGuilds);
},
hasGuildsIntent ? waitGuildTimeout : 0,
).unref();
@@ -553,7 +556,7 @@ class WebSocketShard extends EventEmitter {
*/
sendHeartbeat(
tag = 'HeartbeatTimer',
ignoreHeartbeatAck = [Status.WAITING_FOR_GUILDS, Status.IDENTIFYING, Status.RESUMING].includes(this.status),
ignoreHeartbeatAck = [Status.WaitingForGuilds, Status.Identifying, Status.Resuming].includes(this.status),
) {
if (ignoreHeartbeatAck && !this.lastHeartbeatAcked) {
this.debug(`[${tag}] Didn't process heartbeat ack yet but we are still connected. Sending one now.`);
@@ -572,7 +575,7 @@ class WebSocketShard extends EventEmitter {
this.debug(`[${tag}] Sending a heartbeat.`);
this.lastHeartbeatAcked = false;
this.lastPingTimestamp = Date.now();
this.send({ op: Opcodes.HEARTBEAT, d: this.sequence }, true);
this.send({ op: GatewayOpcodes.Heartbeat, d: this.sequence }, true);
}
/**
@@ -606,7 +609,7 @@ class WebSocketShard extends EventEmitter {
return;
}
this.status = Status.IDENTIFYING;
this.status = Status.Identifying;
// Clone the identify payload and assign the token and shard info
const d = {
@@ -617,7 +620,7 @@ class WebSocketShard extends EventEmitter {
};
this.debug(`[IDENTIFY] Shard ${this.id}/${client.options.shardCount} with intents: ${d.intents}`);
this.send({ op: Opcodes.IDENTIFY, d }, true);
this.send({ op: GatewayOpcodes.Identify, d }, true);
}
/**
@@ -631,7 +634,7 @@ class WebSocketShard extends EventEmitter {
return;
}
this.status = Status.RESUMING;
this.status = Status.Resuming;
this.debug(`[RESUME] Session ${this.sessionId}, sequence ${this.closeSequence}`);
@@ -641,7 +644,7 @@ class WebSocketShard extends EventEmitter {
seq: this.closeSequence,
};
this.send({ op: Opcodes.RESUME, d }, true);
this.send({ op: GatewayOpcodes.Resume, d }, true);
}
/**
@@ -671,7 +674,7 @@ class WebSocketShard extends EventEmitter {
}
this.connection.send(WebSocket.pack(data), err => {
if (err) this.manager.client.emit(Events.SHARD_ERROR, err, this.id);
if (err) this.manager.client.emit(Events.ShardError, err, this.id);
});
}
@@ -741,8 +744,8 @@ class WebSocketShard extends EventEmitter {
// Step 2: Null the connection object
this.connection = null;
// Step 3: Set the shard status to DISCONNECTED
this.status = Status.DISCONNECTED;
// Step 3: Set the shard status to Disconnected
this.status = Status.Disconnected;
// Step 4: Cache the old sequence (use to attempt a resume)
if (this.sequence !== -1) this.closeSequence = this.sequence;
@@ -780,7 +783,7 @@ class WebSocketShard extends EventEmitter {
* @private
* @event WebSocketShard#destroyed
*/
this.emit(ShardEvents.DESTROYED);
this.emit(ShardEvents.Destroyed);
}
}

View File

@@ -1,6 +1,6 @@
'use strict';
const { Events } = require('../../../util/Constants');
const Events = require('../../../util/Events');
module.exports = (client, { d: data }) => {
const channel = client.channels.cache.get(data.channel_id);
@@ -17,6 +17,6 @@ module.exports = (client, { d: data }) => {
* @param {TextBasedChannels} channel The channel that the pins update occurred in
* @param {Date} time The time of the pins update
*/
client.emit(Events.CHANNEL_PINS_UPDATE, channel, time);
client.emit(Events.ChannelPinsUpdate, channel, time);
}
};

View File

@@ -1,6 +1,6 @@
'use strict';
const { Events } = require('../../../util/Constants');
const Events = require('../../../util/Events');
module.exports = (client, packet) => {
const { old, updated } = client.actions.ChannelUpdate.handle(packet.d);
@@ -11,6 +11,6 @@ module.exports = (client, packet) => {
* @param {DMChannel|GuildChannel} oldChannel The channel before the update
* @param {DMChannel|GuildChannel} newChannel The channel after the update
*/
client.emit(Events.CHANNEL_UPDATE, old, updated);
client.emit(Events.ChannelUpdate, old, updated);
}
};

View File

@@ -1,6 +1,7 @@
'use strict';
const { Events, Status } = require('../../../util/Constants');
const Events = require('../../../util/Events');
const Status = require('../../../util/Status');
module.exports = (client, { d: data }, shard) => {
let guild = client.guilds.cache.get(data.id);
@@ -13,13 +14,13 @@ module.exports = (client, { d: data }, shard) => {
// A new guild
data.shardId = shard.id;
guild = client.guilds._add(data);
if (client.ws.status === Status.READY) {
if (client.ws.status === Status.Ready) {
/**
* Emitted whenever the client joins a guild.
* @event Client#guildCreate
* @param {Guild} guild The created guild
*/
client.emit(Events.GUILD_CREATE, guild);
client.emit(Events.GuildCreate, guild);
}
}
};

View File

@@ -1,7 +1,7 @@
'use strict';
const { Collection } = require('@discordjs/collection');
const { Events } = require('../../../util/Constants');
const Events = require('../../../util/Events');
module.exports = (client, { d: data }) => {
const guild = client.guilds.cache.get(data.guild_id);
@@ -28,7 +28,7 @@ module.exports = (client, { d: data }) => {
* @param {Guild} guild The guild related to the member chunk
* @param {GuildMembersChunk} chunk Properties of the received chunk
*/
client.emit(Events.GUILD_MEMBERS_CHUNK, members, guild, {
client.emit(Events.GuildMembersChunk, members, guild, {
count: data.chunk_count,
index: data.chunk_index,
nonce: data.nonce,

View File

@@ -1,19 +1,20 @@
'use strict';
const { Events, Status } = require('../../../util/Constants');
const Events = require('../../../util/Events');
const Status = require('../../../util/Status');
module.exports = (client, { d: data }, shard) => {
const guild = client.guilds.cache.get(data.guild_id);
if (guild) {
guild.memberCount++;
const member = guild.members._add(data);
if (shard.status === Status.READY) {
if (shard.status === Status.Ready) {
/**
* Emitted whenever a user joins a guild.
* @event Client#guildMemberAdd
* @param {GuildMember} member The member that has joined a guild
*/
client.emit(Events.GUILD_MEMBER_ADD, member);
client.emit(Events.GuildMemberAdd, member);
}
}
};

View File

@@ -1,6 +1,6 @@
'use strict';
const { Events } = require('../../../util/Constants');
const Events = require('../../../util/Events');
module.exports = (client, packet) => {
const { old, updated } = client.actions.MessageUpdate.handle(packet.d);
@@ -11,6 +11,6 @@ module.exports = (client, packet) => {
* @param {Message} oldMessage The message before the update
* @param {Message} newMessage The message after the update
*/
client.emit(Events.MESSAGE_UPDATE, old, updated);
client.emit(Events.MessageUpdate, old, updated);
}
};

View File

@@ -1,6 +1,6 @@
'use strict';
const { Events } = require('../../../util/Constants');
const Events = require('../../../util/Events');
module.exports = (client, packet, shard) => {
const replayed = shard.sequence - shard.closeSequence;
@@ -10,5 +10,5 @@ module.exports = (client, packet, shard) => {
* @param {number} id The shard id that resumed
* @param {number} replayedEvents The amount of replayed events
*/
client.emit(Events.SHARD_RESUME, shard.id, replayed);
client.emit(Events.ShardResume, shard.id, replayed);
};

View File

@@ -1,6 +1,6 @@
'use strict';
const { Events } = require('../../../util/Constants');
const Events = require('../../../util/Events');
module.exports = (client, packet) => {
const { old, updated } = client.actions.ChannelUpdate.handle(packet.d);
@@ -11,6 +11,6 @@ module.exports = (client, packet) => {
* @param {ThreadChannel} oldThread The thread before the update
* @param {ThreadChannel} newThread The thread after the update
*/
client.emit(Events.THREAD_UPDATE, old, updated);
client.emit(Events.ThreadUpdate, old, updated);
}
};

View File

@@ -15,8 +15,10 @@ exports.BaseManager = require('./managers/BaseManager');
exports.BitField = require('./util/BitField');
exports.Collection = require('@discordjs/collection').Collection;
exports.Constants = require('./util/Constants');
exports.Colors = require('./util/Colors');
exports.DataResolver = require('./util/DataResolver');
exports.EnumResolvers = require('./util/EnumResolvers');
exports.Events = require('./util/Events');
exports.Formatters = require('./util/Formatters');
exports.IntentsBitField = require('./util/IntentsBitField');
exports.LimitedCollection = require('./util/LimitedCollection');
@@ -24,6 +26,8 @@ exports.MessageFlagsBitField = require('./util/MessageFlagsBitField');
exports.Options = require('./util/Options');
exports.Partials = require('./util/Partials');
exports.PermissionsBitField = require('./util/PermissionsBitField');
exports.ShardEvents = require('./util/ShardEvents');
exports.Status = require('./util/Status');
exports.SnowflakeUtil = require('@sapphire/snowflake').DiscordSnowflake;
exports.Sweepers = require('./util/Sweepers');
exports.SystemChannelFlagsBitField = require('./util/SystemChannelFlagsBitField');
@@ -161,6 +165,7 @@ exports.ButtonStyle = require('discord-api-types/v9').ButtonStyle;
exports.ChannelType = require('discord-api-types/v9').ChannelType;
exports.ComponentType = require('discord-api-types/v9').ComponentType;
exports.GatewayIntentBits = require('discord-api-types/v9').GatewayIntentBits;
exports.GatewayOpcodes = require('discord-api-types/v9').GatewayOpcodes;
exports.GuildFeature = require('discord-api-types/v9').GuildFeature;
exports.GuildMFALevel = require('discord-api-types/v9').GuildMFALevel;
exports.GuildNSFWLevel = require('discord-api-types/v9').GuildNSFWLevel;

View File

@@ -4,7 +4,8 @@ const process = require('node:process');
const { Routes } = require('discord-api-types/v9');
const CachedManager = require('./CachedManager');
const { Channel } = require('../structures/Channel');
const { Events, ThreadChannelTypes } = require('../util/Constants');
const { ThreadChannelTypes } = require('../util/Constants');
const Events = require('../util/Events');
let cacheWarningEmitted = false;
@@ -48,7 +49,7 @@ class ChannelManager extends CachedManager {
const channel = Channel.create(this.client, data, guild, { allowUnknownGuild, fromInteraction });
if (!channel) {
this.client.emit(Events.DEBUG, `Failed to find guild, or unknown type for channel ${data.id} ${data.type}`);
this.client.emit(Events.Debug, `Failed to find guild, or unknown type for channel ${data.id} ${data.type}`);
return null;
}

View File

@@ -12,8 +12,8 @@ const { GuildMember } = require('../structures/GuildMember');
const Invite = require('../structures/Invite');
const OAuth2Guild = require('../structures/OAuth2Guild');
const { Role } = require('../structures/Role');
const { Events } = require('../util/Constants');
const DataResolver = require('../util/DataResolver');
const Events = require('../util/Events');
const PermissionsBitField = require('../util/PermissionsBitField');
const SystemChannelFlagsBitField = require('../util/SystemChannelFlagsBitField');
const { resolveColor } = require('../util/Util');
@@ -222,16 +222,16 @@ class GuildManager extends CachedManager {
const handleGuild = guild => {
if (guild.id === data.id) {
clearTimeout(timeout);
this.client.removeListener(Events.GUILD_CREATE, handleGuild);
this.client.removeListener(Events.GuildCreate, handleGuild);
this.client.decrementMaxListeners();
resolve(guild);
}
};
this.client.incrementMaxListeners();
this.client.on(Events.GUILD_CREATE, handleGuild);
this.client.on(Events.GuildCreate, handleGuild);
const timeout = setTimeout(() => {
this.client.removeListener(Events.GUILD_CREATE, handleGuild);
this.client.removeListener(Events.GuildCreate, handleGuild);
this.client.decrementMaxListeners();
resolve(this.client.guilds._add(data));
}, 10_000).unref();

View File

@@ -4,13 +4,13 @@ const { Buffer } = require('node:buffer');
const { setTimeout, clearTimeout } = require('node:timers');
const { Collection } = require('@discordjs/collection');
const { DiscordSnowflake } = require('@sapphire/snowflake');
const { Routes } = require('discord-api-types/v9');
const { Routes, GatewayOpcodes } = require('discord-api-types/v9');
const CachedManager = require('./CachedManager');
const { Error, TypeError, RangeError } = require('../errors');
const BaseGuildVoiceChannel = require('../structures/BaseGuildVoiceChannel');
const { GuildMember } = require('../structures/GuildMember');
const { Role } = require('../structures/Role');
const { Events, Opcodes } = require('../util/Constants');
const Events = require('../util/Events');
/**
* Manages API methods for GuildMembers and stores their cache.
@@ -430,7 +430,7 @@ class GuildMemberManager extends CachedManager {
if (!query && !user_ids) query = '';
if (nonce.length > 32) throw new RangeError('MEMBER_FETCH_NONCE_LENGTH');
this.guild.shard.send({
op: Opcodes.REQUEST_GUILD_MEMBERS,
op: GatewayOpcodes.RequestGuildMembers,
d: {
guild_id: this.guild.id,
presences,
@@ -451,7 +451,7 @@ class GuildMemberManager extends CachedManager {
}
if (members.size < 1_000 || (limit && fetchedMembers.size >= limit) || i === chunk.count) {
clearTimeout(timeout);
this.client.removeListener(Events.GUILD_MEMBERS_CHUNK, handler);
this.client.removeListener(Events.GuildMembersChunk, handler);
this.client.decrementMaxListeners();
let fetched = fetchedMembers;
if (user_ids && !Array.isArray(user_ids) && fetched.size) fetched = fetched.first();
@@ -459,12 +459,12 @@ class GuildMemberManager extends CachedManager {
}
};
const timeout = setTimeout(() => {
this.client.removeListener(Events.GUILD_MEMBERS_CHUNK, handler);
this.client.removeListener(Events.GuildMembersChunk, handler);
this.client.decrementMaxListeners();
reject(new Error('GUILD_MEMBERS_TIMEOUT'));
}, time).unref();
this.client.incrementMaxListeners();
this.client.on(Events.GUILD_MEMBERS_CHUNK, handler);
this.client.on(Events.GuildMembersChunk, handler);
});
}
}

View File

@@ -128,7 +128,7 @@ class RoleManager extends CachedManager {
* // Create a new role with data and a reason
* guild.roles.create({
* name: 'Super Cool Blue People',
* color: 'BLUE',
* color: Colors.Blue,
* reason: 'we needed a role for Super Cool People',
* })
* .then(console.log)

View File

@@ -2,7 +2,7 @@
const process = require('node:process');
const { Error } = require('../errors');
const { Events } = require('../util/Constants');
const Events = require('../util/Events');
const Util = require('../util/Util');
/**
@@ -216,7 +216,7 @@ class ShardClientUtil {
* @event Client#error
* @param {Error} error The error encountered
*/
this.client.emit(Events.ERROR, error);
this.client.emit(Events.Error, error);
});
}
@@ -231,7 +231,7 @@ class ShardClientUtil {
this._singleton = new this(client, mode);
} else {
client.emit(
Events.WARN,
Events.Warn,
'Multiple clients created in child process/worker; only the first will handle sharding helpers.',
);
}

View File

@@ -1,8 +1,8 @@
'use strict';
const { GatewayOpcodes } = require('discord-api-types/v9');
const { Presence } = require('./Presence');
const { TypeError } = require('../errors');
const { Opcodes } = require('../util/Constants');
/**
* Represents the client's presence.
@@ -22,13 +22,13 @@ class ClientPresence extends Presence {
const packet = this._parse(presence);
this._patch(packet);
if (typeof presence.shardId === 'undefined') {
this.client.ws.broadcast({ op: Opcodes.STATUS_UPDATE, d: packet });
this.client.ws.broadcast({ op: GatewayOpcodes.StatusUpdate, d: packet });
} else if (Array.isArray(presence.shardId)) {
for (const shardId of presence.shardId) {
this.client.ws.shards.get(shardId).send({ op: Opcodes.STATUS_UPDATE, d: packet });
this.client.ws.shards.get(shardId).send({ op: GatewayOpcodes.StatusUpdate, d: packet });
}
} else {
this.client.ws.shards.get(presence.shardId).send({ op: Opcodes.STATUS_UPDATE, d: packet });
this.client.ws.shards.get(presence.shardId).send({ op: GatewayOpcodes.StatusUpdate, d: packet });
}
return this;
}

View File

@@ -22,9 +22,9 @@ const PresenceManager = require('../managers/PresenceManager');
const RoleManager = require('../managers/RoleManager');
const StageInstanceManager = require('../managers/StageInstanceManager');
const VoiceStateManager = require('../managers/VoiceStateManager');
const { Status } = require('../util/Constants');
const DataResolver = require('../util/DataResolver');
const Partials = require('../util/Partials');
const Status = require('../util/Status');
const SystemChannelFlagsBitField = require('../util/SystemChannelFlagsBitField');
const Util = require('../util/Util');
@@ -1244,7 +1244,7 @@ class Guild extends AnonymousGuild {
this.client.voice.adapters.set(this.id, methods);
return {
sendPayload: data => {
if (this.shard.status !== Status.READY) return false;
if (this.shard.status !== Status.Ready) return false;
this.shard.send(data);
return true;
},

View File

@@ -3,8 +3,8 @@
const { setTimeout, clearTimeout } = require('node:timers');
const { RouteBases, Routes } = require('discord-api-types/v9');
const Base = require('./Base');
const { Events } = require('../util/Constants');
const DataResolver = require('../util/DataResolver');
const Events = require('../util/Events');
/**
* Represents the template for a guild.
@@ -126,7 +126,7 @@ class GuildTemplate extends Base {
return new Promise(resolve => {
const resolveGuild = guild => {
client.off(Events.GUILD_CREATE, handleGuild);
client.off(Events.GuildCreate, handleGuild);
client.decrementMaxListeners();
resolve(guild);
};
@@ -139,7 +139,7 @@ class GuildTemplate extends Base {
};
client.incrementMaxListeners();
client.on(Events.GUILD_CREATE, handleGuild);
client.on(Events.GuildCreate, handleGuild);
const timeout = setTimeout(() => resolveGuild(client.guilds._add(data)), 10_000).unref();
});

View File

@@ -2,7 +2,7 @@
const { Collection } = require('@discordjs/collection');
const Collector = require('./interfaces/Collector');
const { Events } = require('../util/Constants');
const Events = require('../util/Events');
/**
* @typedef {CollectorOptions} InteractionCollectorOptions
@@ -92,31 +92,31 @@ class InteractionCollector extends Collector {
if (this.messageId) {
this._handleMessageDeletion = this._handleMessageDeletion.bind(this);
this.client.on(Events.MESSAGE_DELETE, this._handleMessageDeletion);
this.client.on(Events.MESSAGE_BULK_DELETE, bulkDeleteListener);
this.client.on(Events.MessageDelete, this._handleMessageDeletion);
this.client.on(Events.MessageBulkDelete, bulkDeleteListener);
}
if (this.channelId) {
this._handleChannelDeletion = this._handleChannelDeletion.bind(this);
this._handleThreadDeletion = this._handleThreadDeletion.bind(this);
this.client.on(Events.CHANNEL_DELETE, this._handleChannelDeletion);
this.client.on(Events.THREAD_DELETE, this._handleThreadDeletion);
this.client.on(Events.ChannelDelete, this._handleChannelDeletion);
this.client.on(Events.ThreadDelete, this._handleThreadDeletion);
}
if (this.guildId) {
this._handleGuildDeletion = this._handleGuildDeletion.bind(this);
this.client.on(Events.GUILD_DELETE, this._handleGuildDeletion);
this.client.on(Events.GuildDelete, this._handleGuildDeletion);
}
this.client.on(Events.INTERACTION_CREATE, this.handleCollect);
this.client.on(Events.InteractionCreate, this.handleCollect);
this.once('end', () => {
this.client.removeListener(Events.INTERACTION_CREATE, this.handleCollect);
this.client.removeListener(Events.MESSAGE_DELETE, this._handleMessageDeletion);
this.client.removeListener(Events.MESSAGE_BULK_DELETE, bulkDeleteListener);
this.client.removeListener(Events.CHANNEL_DELETE, this._handleChannelDeletion);
this.client.removeListener(Events.THREAD_DELETE, this._handleThreadDeletion);
this.client.removeListener(Events.GUILD_DELETE, this._handleGuildDeletion);
this.client.removeListener(Events.InteractionCreate, this.handleCollect);
this.client.removeListener(Events.MessageDelete, this._handleMessageDeletion);
this.client.removeListener(Events.MessageBulkDelete, bulkDeleteListener);
this.client.removeListener(Events.ChannelDelete, this._handleChannelDeletion);
this.client.removeListener(Events.ThreadDelete, this._handleThreadDeletion);
this.client.removeListener(Events.GuildDelete, this._handleGuildDeletion);
this.client.decrementMaxListeners();
});

View File

@@ -1,7 +1,7 @@
'use strict';
const Collector = require('./interfaces/Collector');
const { Events } = require('../util/Constants');
const Events = require('../util/Events');
/**
* @typedef {CollectorOptions} MessageCollectorOptions
@@ -46,20 +46,20 @@ class MessageCollector extends Collector {
this._handleGuildDeletion = this._handleGuildDeletion.bind(this);
this.client.incrementMaxListeners();
this.client.on(Events.MESSAGE_CREATE, this.handleCollect);
this.client.on(Events.MESSAGE_DELETE, this.handleDispose);
this.client.on(Events.MESSAGE_BULK_DELETE, bulkDeleteListener);
this.client.on(Events.CHANNEL_DELETE, this._handleChannelDeletion);
this.client.on(Events.THREAD_DELETE, this._handleThreadDeletion);
this.client.on(Events.GUILD_DELETE, this._handleGuildDeletion);
this.client.on(Events.MessageCreate, this.handleCollect);
this.client.on(Events.MessageDelete, this.handleDispose);
this.client.on(Events.MessageBulkDelete, bulkDeleteListener);
this.client.on(Events.ChannelDelete, this._handleChannelDeletion);
this.client.on(Events.ThreadDelete, this._handleThreadDeletion);
this.client.on(Events.GuildDelete, this._handleGuildDeletion);
this.once('end', () => {
this.client.removeListener(Events.MESSAGE_CREATE, this.handleCollect);
this.client.removeListener(Events.MESSAGE_DELETE, this.handleDispose);
this.client.removeListener(Events.MESSAGE_BULK_DELETE, bulkDeleteListener);
this.client.removeListener(Events.CHANNEL_DELETE, this._handleChannelDeletion);
this.client.removeListener(Events.THREAD_DELETE, this._handleThreadDeletion);
this.client.removeListener(Events.GUILD_DELETE, this._handleGuildDeletion);
this.client.removeListener(Events.MessageCreate, this.handleCollect);
this.client.removeListener(Events.MessageDelete, this.handleDispose);
this.client.removeListener(Events.MessageBulkDelete, bulkDeleteListener);
this.client.removeListener(Events.ChannelDelete, this._handleChannelDeletion);
this.client.removeListener(Events.ThreadDelete, this._handleThreadDeletion);
this.client.removeListener(Events.GuildDelete, this._handleGuildDeletion);
this.client.decrementMaxListeners();
});
}

View File

@@ -2,7 +2,7 @@
const { Collection } = require('@discordjs/collection');
const Collector = require('./interfaces/Collector');
const { Events } = require('../util/Constants');
const Events = require('../util/Events');
/**
* @typedef {CollectorOptions} ReactionCollectorOptions
@@ -57,24 +57,24 @@ class ReactionCollector extends Collector {
};
this.client.incrementMaxListeners();
this.client.on(Events.MESSAGE_REACTION_ADD, this.handleCollect);
this.client.on(Events.MESSAGE_REACTION_REMOVE, this.handleDispose);
this.client.on(Events.MESSAGE_REACTION_REMOVE_ALL, this.empty);
this.client.on(Events.MESSAGE_DELETE, this._handleMessageDeletion);
this.client.on(Events.MESSAGE_BULK_DELETE, bulkDeleteListener);
this.client.on(Events.CHANNEL_DELETE, this._handleChannelDeletion);
this.client.on(Events.THREAD_DELETE, this._handleThreadDeletion);
this.client.on(Events.GUILD_DELETE, this._handleGuildDeletion);
this.client.on(Events.MessageReactionAdd, this.handleCollect);
this.client.on(Events.MessageReactionRemove, this.handleDispose);
this.client.on(Events.MessageReactionRemoveAll, this.empty);
this.client.on(Events.MessageDelete, this._handleMessageDeletion);
this.client.on(Events.MessageBulkDelete, bulkDeleteListener);
this.client.on(Events.ChannelDelete, this._handleChannelDeletion);
this.client.on(Events.ThreadDelete, this._handleThreadDeletion);
this.client.on(Events.GuildDelete, this._handleGuildDeletion);
this.once('end', () => {
this.client.removeListener(Events.MESSAGE_REACTION_ADD, this.handleCollect);
this.client.removeListener(Events.MESSAGE_REACTION_REMOVE, this.handleDispose);
this.client.removeListener(Events.MESSAGE_REACTION_REMOVE_ALL, this.empty);
this.client.removeListener(Events.MESSAGE_DELETE, this._handleMessageDeletion);
this.client.removeListener(Events.MESSAGE_BULK_DELETE, bulkDeleteListener);
this.client.removeListener(Events.CHANNEL_DELETE, this._handleChannelDeletion);
this.client.removeListener(Events.THREAD_DELETE, this._handleThreadDeletion);
this.client.removeListener(Events.GUILD_DELETE, this._handleGuildDeletion);
this.client.removeListener(Events.MessageReactionAdd, this.handleCollect);
this.client.removeListener(Events.MessageReactionRemove, this.handleDispose);
this.client.removeListener(Events.MessageReactionRemoveAll, this.empty);
this.client.removeListener(Events.MessageDelete, this._handleMessageDeletion);
this.client.removeListener(Events.MessageBulkDelete, bulkDeleteListener);
this.client.removeListener(Events.ChannelDelete, this._handleChannelDeletion);
this.client.removeListener(Events.ThreadDelete, this._handleThreadDeletion);
this.client.removeListener(Events.GuildDelete, this._handleGuildDeletion);
this.client.decrementMaxListeners();
});

View File

@@ -0,0 +1,34 @@
'use strict';
module.exports = {
Default: 0x000000,
White: 0xffffff,
Aqua: 0x1abc9c,
Green: 0x57f287,
Blue: 0x3498db,
Yellow: 0xfee75c,
Purple: 0x9b59b6,
LuminousVividPink: 0xe91e63,
Fuchsia: 0xeb459e,
Gold: 0xf1c40f,
Orange: 0xe67e22,
Red: 0xed4245,
Grey: 0x95a5a6,
Navy: 0x34495e,
DarkAqua: 0x11806a,
DarkGreen: 0x1f8b4c,
DarkBlue: 0x206694,
DarkPurple: 0x71368a,
DarkVividPink: 0xad1457,
DarkGold: 0xc27c0e,
DarkOrange: 0xa84300,
DarkRed: 0x992d22,
DarkGrey: 0x979c9f,
DarkerGrey: 0x7f8c8d,
LightGrey: 0xbcc0c0,
DarkNavy: 0x2c3e50,
Blurple: 0x5865f2,
Greyple: 0x99aab5,
DarkButNotBlack: 0x2c2f33,
NotQuiteBlack: 0x23272a,
};

View File

@@ -15,126 +15,6 @@ exports.WSCodes = {
4014: 'DISALLOWED_INTENTS',
};
/**
* The current status of the client. Here are the available statuses:
* * READY: 0
* * CONNECTING: 1
* * RECONNECTING: 2
* * IDLE: 3
* * NEARLY: 4
* * DISCONNECTED: 5
* * WAITING_FOR_GUILDS: 6
* * IDENTIFYING: 7
* * RESUMING: 8
* @typedef {number} Status
*/
exports.Status = {
READY: 0,
CONNECTING: 1,
RECONNECTING: 2,
IDLE: 3,
NEARLY: 4,
DISCONNECTED: 5,
WAITING_FOR_GUILDS: 6,
IDENTIFYING: 7,
RESUMING: 8,
};
exports.Opcodes = {
DISPATCH: 0,
HEARTBEAT: 1,
IDENTIFY: 2,
STATUS_UPDATE: 3,
VOICE_STATE_UPDATE: 4,
VOICE_GUILD_PING: 5,
RESUME: 6,
RECONNECT: 7,
REQUEST_GUILD_MEMBERS: 8,
INVALID_SESSION: 9,
HELLO: 10,
HEARTBEAT_ACK: 11,
};
exports.Events = {
CLIENT_READY: 'ready',
GUILD_CREATE: 'guildCreate',
GUILD_DELETE: 'guildDelete',
GUILD_UPDATE: 'guildUpdate',
GUILD_UNAVAILABLE: 'guildUnavailable',
GUILD_MEMBER_ADD: 'guildMemberAdd',
GUILD_MEMBER_REMOVE: 'guildMemberRemove',
GUILD_MEMBER_UPDATE: 'guildMemberUpdate',
GUILD_MEMBER_AVAILABLE: 'guildMemberAvailable',
GUILD_MEMBERS_CHUNK: 'guildMembersChunk',
GUILD_INTEGRATIONS_UPDATE: 'guildIntegrationsUpdate',
GUILD_ROLE_CREATE: 'roleCreate',
GUILD_ROLE_DELETE: 'roleDelete',
INVITE_CREATE: 'inviteCreate',
INVITE_DELETE: 'inviteDelete',
GUILD_ROLE_UPDATE: 'roleUpdate',
GUILD_EMOJI_CREATE: 'emojiCreate',
GUILD_EMOJI_DELETE: 'emojiDelete',
GUILD_EMOJI_UPDATE: 'emojiUpdate',
GUILD_BAN_ADD: 'guildBanAdd',
GUILD_BAN_REMOVE: 'guildBanRemove',
CHANNEL_CREATE: 'channelCreate',
CHANNEL_DELETE: 'channelDelete',
CHANNEL_UPDATE: 'channelUpdate',
CHANNEL_PINS_UPDATE: 'channelPinsUpdate',
MESSAGE_CREATE: 'messageCreate',
MESSAGE_DELETE: 'messageDelete',
MESSAGE_UPDATE: 'messageUpdate',
MESSAGE_BULK_DELETE: 'messageDeleteBulk',
MESSAGE_REACTION_ADD: 'messageReactionAdd',
MESSAGE_REACTION_REMOVE: 'messageReactionRemove',
MESSAGE_REACTION_REMOVE_ALL: 'messageReactionRemoveAll',
MESSAGE_REACTION_REMOVE_EMOJI: 'messageReactionRemoveEmoji',
THREAD_CREATE: 'threadCreate',
THREAD_DELETE: 'threadDelete',
THREAD_UPDATE: 'threadUpdate',
THREAD_LIST_SYNC: 'threadListSync',
THREAD_MEMBER_UPDATE: 'threadMemberUpdate',
THREAD_MEMBERS_UPDATE: 'threadMembersUpdate',
USER_UPDATE: 'userUpdate',
PRESENCE_UPDATE: 'presenceUpdate',
VOICE_SERVER_UPDATE: 'voiceServerUpdate',
VOICE_STATE_UPDATE: 'voiceStateUpdate',
TYPING_START: 'typingStart',
WEBHOOKS_UPDATE: 'webhookUpdate',
INTERACTION_CREATE: 'interactionCreate',
ERROR: 'error',
WARN: 'warn',
DEBUG: 'debug',
CACHE_SWEEP: 'cacheSweep',
SHARD_DISCONNECT: 'shardDisconnect',
SHARD_ERROR: 'shardError',
SHARD_RECONNECTING: 'shardReconnecting',
SHARD_READY: 'shardReady',
SHARD_RESUME: 'shardResume',
INVALIDATED: 'invalidated',
RAW: 'raw',
STAGE_INSTANCE_CREATE: 'stageInstanceCreate',
STAGE_INSTANCE_UPDATE: 'stageInstanceUpdate',
STAGE_INSTANCE_DELETE: 'stageInstanceDelete',
GUILD_STICKER_CREATE: 'stickerCreate',
GUILD_STICKER_DELETE: 'stickerDelete',
GUILD_STICKER_UPDATE: 'stickerUpdate',
GUILD_SCHEDULED_EVENT_CREATE: 'guildScheduledEventCreate',
GUILD_SCHEDULED_EVENT_UPDATE: 'guildScheduledEventUpdate',
GUILD_SCHEDULED_EVENT_DELETE: 'guildScheduledEventDelete',
GUILD_SCHEDULED_EVENT_USER_ADD: 'guildScheduledEventUserAdd',
GUILD_SCHEDULED_EVENT_USER_REMOVE: 'guildScheduledEventUserRemove',
};
exports.ShardEvents = {
CLOSE: 'close',
DESTROYED: 'destroyed',
INVALID_SESSION: 'invalidSession',
READY: 'ready',
RESUMED: 'resumed',
ALL_READY: 'allReady',
};
/**
* The type of a WebSocket message event, e.g. `MESSAGE_CREATE`. Here are the available events:
* * READY
@@ -379,39 +259,6 @@ exports.ThreadChannelTypes = [
*/
exports.VoiceBasedChannelTypes = [ChannelType.GuildVoice, ChannelType.GuildStageVoice];
exports.Colors = {
DEFAULT: 0x000000,
WHITE: 0xffffff,
AQUA: 0x1abc9c,
GREEN: 0x57f287,
BLUE: 0x3498db,
YELLOW: 0xfee75c,
PURPLE: 0x9b59b6,
LUMINOUS_VIVID_PINK: 0xe91e63,
FUCHSIA: 0xeb459e,
GOLD: 0xf1c40f,
ORANGE: 0xe67e22,
RED: 0xed4245,
GREY: 0x95a5a6,
NAVY: 0x34495e,
DARK_AQUA: 0x11806a,
DARK_GREEN: 0x1f8b4c,
DARK_BLUE: 0x206694,
DARK_PURPLE: 0x71368a,
DARK_VIVID_PINK: 0xad1457,
DARK_GOLD: 0xc27c0e,
DARK_ORANGE: 0xa84300,
DARK_RED: 0x992d22,
DARK_GREY: 0x979c9f,
DARKER_GREY: 0x7f8c8d,
LIGHT_GREY: 0xbcc0c0,
DARK_NAVY: 0x2c3e50,
BLURPLE: 0x5865f2,
GREYPLE: 0x99aab5,
DARK_BUT_NOT_BLACK: 0x2c2f33,
NOT_QUITE_BLACK: 0x23272a,
};
/* eslint-enable max-len */
function keyMirror(arr) {

View File

@@ -0,0 +1,13 @@
'use strict';
function createEnum(keys) {
const obj = {};
for (const [index, key] of keys.entries()) {
if (key === null) continue;
obj[key] = index;
obj[index] = key;
}
return obj;
}
module.exports = { createEnum };

View File

@@ -0,0 +1,72 @@
'use strict';
module.exports = {
ClientReady: 'ready',
GuildCreate: 'guildCreate',
GuildDelete: 'guildDelete',
GuildUpdate: 'guildUpdate',
GuildUnavailable: 'guildUnavailable',
GuildMemberAdd: 'guildMemberAdd',
GuildMemberRemove: 'guildMemberRemove',
GuildMemberUpdate: 'guildMemberUpdate',
GuildMemberAvailable: 'guildMemberAvailable',
GuildMembersChunk: 'guildMembersChunk',
GuildIntegrationsUpdate: 'guildIntegrationsUpdate',
GuildRoleCreate: 'roleCreate',
GuildRoleDelete: 'roleDelete',
InviteCreate: 'inviteCreate',
InviteDelete: 'inviteDelete',
GuildRoleUpdate: 'roleUpdate',
GuildEmojiCreate: 'emojiCreate',
GuildEmojiDelete: 'emojiDelete',
GuildEmojiUpdate: 'emojiUpdate',
GuildBanAdd: 'guildBanAdd',
GuildBanRemove: 'guildBanRemove',
ChannelCreate: 'channelCreate',
ChannelDelete: 'channelDelete',
ChannelUpdate: 'channelUpdate',
ChannelPinsUpdate: 'channelPinsUpdate',
MessageCreate: 'messageCreate',
MessageDelete: 'messageDelete',
MessageUpdate: 'messageUpdate',
MessageBulkDelete: 'messageDeleteBulk',
MessageReactionAdd: 'messageReactionAdd',
MessageReactionRemove: 'messageReactionRemove',
MessageReactionRemoveAll: 'messageReactionRemoveAll',
MessageReactionRemoveEmoji: 'messageReactionRemoveEmoji',
ThreadCreate: 'threadCreate',
ThreadDelete: 'threadDelete',
ThreadUpdate: 'threadUpdate',
ThreadListSync: 'threadListSync',
ThreadMemberUpdate: 'threadMemberUpdate',
ThreadMembersUpdate: 'threadMembersUpdate',
UserUpdate: 'userUpdate',
PresenceUpdate: 'presenceUpdate',
VoiceServerUpdate: 'voiceServerUpdate',
VoiceStateUpdate: 'voiceStateUpdate',
TypingStart: 'typingStart',
WebhooksUpdate: 'webhookUpdate',
InteractionCreate: 'interactionCreate',
Error: 'error',
Warn: 'warn',
Debug: 'debug',
CacheSweep: 'cacheSweep',
ShardDisconnect: 'shardDisconnect',
ShardError: 'shardError',
ShardReconnecting: 'shardReconnecting',
ShardReady: 'shardReady',
ShardResume: 'shardResume',
Invalidated: 'invalidated',
Raw: 'raw',
StageInstanceCreate: 'stageInstanceCreate',
StageInstanceUpdate: 'stageInstanceUpdate',
StageInstanceDelete: 'stageInstanceDelete',
GuildStickerCreate: 'stickerCreate',
GuildStickerDelete: 'stickerDelete',
GuildStickerUpdate: 'stickerUpdate',
GuildScheduledEventCreate: 'guildScheduledEventCreate',
GuildScheduledEventUpdate: 'guildScheduledEventUpdate',
GuildScheduledEventDelete: 'guildScheduledEventDelete',
GuildScheduledEventUserAdd: 'guildScheduledEventUserAdd',
GuildScheduledEventUserRemove: 'guildScheduledEventUserRemove',
};

View File

@@ -1,13 +1,5 @@
'use strict';
function createEnum(keys) {
const obj = {};
for (const [index, key] of keys.entries()) {
if (key === null) continue;
obj[key] = index;
obj[index] = key;
}
return obj;
}
const { createEnum } = require('./Enums');
module.exports = createEnum(['User', 'Channel', 'GuildMember', 'Message', 'Reaction', 'GuildScheduledEvent']);

View File

@@ -0,0 +1,10 @@
'use strict';
module.exports = {
Close: 'close',
Destroyed: 'destroyed',
InvalidSession: 'invalidSession',
Ready: 'ready',
Resumed: 'resumed',
AllReady: 'allReady',
};

View File

@@ -0,0 +1,15 @@
'use strict';
const { createEnum } = require('./Enums');
module.exports = createEnum([
'Ready',
'Connecting',
'Reconnecting',
'Idle',
'Nearly',
'Disconnected',
'WaitingForGuilds',
'Identifying',
'Resuming',
]);

View File

@@ -1,7 +1,8 @@
'use strict';
const { setInterval, clearInterval } = require('node:timers');
const { Events, ThreadChannelTypes, SweeperKeys } = require('./Constants');
const { ThreadChannelTypes, SweeperKeys } = require('./Constants');
const Events = require('./Events');
const { TypeError } = require('../errors/DJSError.js');
/**
@@ -71,7 +72,7 @@ class Sweepers {
const globalCommands = this.client.application?.commands.cache.sweep(filter) ?? 0;
this.client.emit(
Events.CACHE_SWEEP,
Events.CacheSweep,
`Swept ${globalCommands} global application commands and ${guildCommands} guild commands in ${guilds} guilds.`,
);
return guildCommands + globalCommands;
@@ -141,7 +142,7 @@ class Sweepers {
channels++;
messages += channel.messages.cache.sweep(filter);
}
this.client.emit(Events.CACHE_SWEEP, `Swept ${messages} messages in ${channels} text-based channels.`);
this.client.emit(Events.CacheSweep, `Swept ${messages} messages in ${channels} text-based channels.`);
return messages;
}
@@ -177,7 +178,7 @@ class Sweepers {
}
}
this.client.emit(
Events.CACHE_SWEEP,
Events.CacheSweep,
`Swept ${reactions} reactions on ${messages} messages in ${channels} text-based channels.`,
);
return reactions;
@@ -219,7 +220,7 @@ class Sweepers {
threads++;
members += channel.members.cache.sweep(filter);
}
this.client.emit(Events.CACHE_SWEEP, `Swept ${members} thread members in ${threads} threads.`);
this.client.emit(Events.CacheSweep, `Swept ${members} thread members in ${threads} threads.`);
return members;
}
@@ -250,7 +251,7 @@ class Sweepers {
this.client.channels._remove(key);
}
}
this.client.emit(Events.CACHE_SWEEP, `Swept ${threads} threads.`);
this.client.emit(Events.CacheSweep, `Swept ${threads} threads.`);
return threads;
}
@@ -266,7 +267,7 @@ class Sweepers {
const users = this.client.users.cache.sweep(filter);
this.client.emit(Events.CACHE_SWEEP, `Swept ${users} users.`);
this.client.emit(Events.CacheSweep, `Swept ${users} users.`);
return users;
}
@@ -404,7 +405,7 @@ class Sweepers {
}
if (emit) {
this.client.emit(Events.CACHE_SWEEP, `Swept ${items} ${outputName ?? key} in ${guilds} guilds.`);
this.client.emit(Events.CacheSweep, `Swept ${items} ${outputName ?? key} in ${guilds} guilds.`);
}
return { guilds, items };

View File

@@ -4,7 +4,7 @@ const { parse } = require('node:path');
const { Collection } = require('@discordjs/collection');
const { ChannelType, RouteBases, Routes } = require('discord-api-types/v9');
const fetch = require('node-fetch');
const { Colors } = require('./Constants');
const Colors = require('./Colors');
const { Error: DiscordError, RangeError, TypeError } = require('../errors');
const isObject = d => typeof d === 'object' && d !== null;
@@ -419,37 +419,37 @@ class Util extends null {
* [255, 0, 255] // purple
* ```
* or one of the following strings:
* - `DEFAULT`
* - `WHITE`
* - `AQUA`
* - `GREEN`
* - `BLUE`
* - `YELLOW`
* - `PURPLE`
* - `LUMINOUS_VIVID_PINK`
* - `FUCHSIA`
* - `GOLD`
* - `ORANGE`
* - `RED`
* - `GREY`
* - `NAVY`
* - `DARK_AQUA`
* - `DARK_GREEN`
* - `DARK_BLUE`
* - `DARK_PURPLE`
* - `DARK_VIVID_PINK`
* - `DARK_GOLD`
* - `DARK_ORANGE`
* - `DARK_RED`
* - `DARK_GREY`
* - `DARKER_GREY`
* - `LIGHT_GREY`
* - `DARK_NAVY`
* - `BLURPLE`
* - `GREYPLE`
* - `DARK_BUT_NOT_BLACK`
* - `NOT_QUITE_BLACK`
* - `RANDOM`
* - `Default`
* - `White`
* - `Aqua`
* - `Green`
* - `Blue`
* - `Yellow`
* - `Purple`
* - `LuminousVividPink`
* - `Fuchsia`
* - `Gold`
* - `Orange`
* - `Red`
* - `Grey`
* - `Navy`
* - `DarkAqua`
* - `DarkGreen`
* - `DarkBlue`
* - `DarkPurple`
* - `DarkVividPink`
* - `DarkGold`
* - `DarkOrange`
* - `DarkRed`
* - `DarkGrey`
* - `DarkerGrey`
* - `LightGrey`
* - `DarkNavy`
* - `Blurple`
* - `Greyple`
* - `DarkButNotBlack`
* - `NotQuiteBlack`
* - `Random`
* @typedef {string|number|number[]} ColorResolvable
*/
@@ -460,8 +460,8 @@ class Util extends null {
*/
static resolveColor(color) {
if (typeof color === 'string') {
if (color === 'RANDOM') return Math.floor(Math.random() * (0xffffff + 1));
if (color === 'DEFAULT') return 0;
if (color === 'Random') return Math.floor(Math.random() * (0xffffff + 1));
if (color === 'Default') return 0;
color = Colors[color] ?? parseInt(color.replace('#', ''), 16);
} else if (Array.isArray(color)) {
color = (color[0] << 16) + (color[1] << 8) + color[2];

View File

@@ -2610,14 +2610,9 @@ export const Constants: {
4010: 'SHARDING_INVALID';
4011: 'SHARDING_REQUIRED';
};
Events: ConstantsEvents;
ShardEvents: ConstantsShardEvents;
WSEvents: {
[K in WSEventType]: K;
};
Colors: ConstantsColors;
Status: ConstantsStatus;
Opcodes: ConstantsOpcodes;
ThreadChannelTypes: ThreadChannelType[];
TextBasedChannelTypes: TextBasedChannelTypes[];
VoiceBasedChannelTypes: VoiceBasedChannelTypes[];
@@ -3601,37 +3596,37 @@ export interface CollectorResetTimerOptions {
}
export type ColorResolvable =
| 'DEFAULT'
| 'WHITE'
| 'AQUA'
| 'GREEN'
| 'BLUE'
| 'YELLOW'
| 'PURPLE'
| 'LUMINOUS_VIVID_PINK'
| 'FUCHSIA'
| 'GOLD'
| 'ORANGE'
| 'RED'
| 'GREY'
| 'DARKER_GREY'
| 'NAVY'
| 'DARK_AQUA'
| 'DARK_GREEN'
| 'DARK_BLUE'
| 'DARK_PURPLE'
| 'DARK_VIVID_PINK'
| 'DARK_GOLD'
| 'DARK_ORANGE'
| 'DARK_RED'
| 'DARK_GREY'
| 'LIGHT_GREY'
| 'DARK_NAVY'
| 'BLURPLE'
| 'GREYPLE'
| 'DARK_BUT_NOT_BLACK'
| 'NOT_QUITE_BLACK'
| 'RANDOM'
| 'Default'
| 'White'
| 'Aqua'
| 'Green'
| 'Blue'
| 'Yellow'
| 'Purple'
| 'LuminousVividPink'
| 'Fuchsia'
| 'Gold'
| 'Orange'
| 'Red'
| 'Grey'
| 'Navy'
| 'DarkAqua'
| 'DarkGreen'
| 'DarkBlue'
| 'DarkPurple'
| 'DarkVividPink'
| 'DarkGold'
| 'DarkOrange'
| 'DarkRed'
| 'DarkGrey'
| 'DarkerGrey'
| 'LightGrey'
| 'DarkNavy'
| 'Blurple'
| 'Greyple'
| 'DarkButNotBlack'
| 'NotQuiteBlack'
| 'Random'
| readonly [number, number, number]
| number
| HexColorString;
@@ -3658,140 +3653,126 @@ export interface CommandInteractionResolvedData<Cached extends CacheType = Cache
messages?: Collection<Snowflake, CacheTypeReducer<Cached, Message, APIMessage>>;
}
export interface ConstantsColors {
DEFAULT: 0x000000;
WHITE: 0xffffff;
AQUA: 0x1abc9c;
GREEN: 0x57f287;
BLUE: 0x3498db;
YELLOW: 0xfee75c;
PURPLE: 0x9b59b6;
LUMINOUS_VIVID_PINK: 0xe91e63;
FUCHSIA: 0xeb459e;
GOLD: 0xf1c40f;
ORANGE: 0xe67e22;
RED: 0xed4245;
GREY: 0x95a5a6;
NAVY: 0x34495e;
DARK_AQUA: 0x11806a;
DARK_GREEN: 0x1f8b4c;
DARK_BLUE: 0x206694;
DARK_PURPLE: 0x71368a;
DARK_VIVID_PINK: 0xad1457;
DARK_GOLD: 0xc27c0e;
DARK_ORANGE: 0xa84300;
DARK_RED: 0x992d22;
DARK_GREY: 0x979c9f;
DARKER_GREY: 0x7f8c8d;
LIGHT_GREY: 0xbcc0c0;
DARK_NAVY: 0x2c3e50;
BLURPLE: 0x5865f2;
GREYPLE: 0x99aab5;
DARK_BUT_NOT_BLACK: 0x2c2f33;
NOT_QUITE_BLACK: 0x23272a;
export declare const Colors: {
Default: 0x000000;
White: 0xffffff;
Aqua: 0x1abc9c;
Green: 0x57f287;
Blue: 0x3498db;
Yellow: 0xfee75c;
Purple: 0x9b59b6;
LuminousVividPink: 0xe91e63;
Fuchsia: 0xeb459e;
Gold: 0xf1c40f;
Orange: 0xe67e22;
Red: 0xed4245;
Grey: 0x95a5a6;
Navy: 0x34495e;
DarkAqua: 0x11806a;
DarkGreen: 0x1f8b4c;
DarkBlue: 0x206694;
DarkPurple: 0x71368a;
DarkVividPink: 0xad1457;
DarkGold: 0xc27c0e;
DarkOrange: 0xa84300;
DarkRed: 0x992d22;
DarkGrey: 0x979c9f;
DarkerGrey: 0x7f8c8d;
LightGrey: 0xbcc0c0;
DarkNavy: 0x2c3e50;
Blurple: 0x5865f2;
Greyple: 0x99aab5;
DarkButNotBlack: 0x2c2f33;
NotQuiteBlack: 0x23272a;
};
export declare const Events: {
ClientReady: 'ready';
GuildCreate: 'guildCreate';
GuildDelete: 'guildDelete';
GuildUpdate: 'guildUpdate';
GuildUnavailable: 'guildUnavailable';
GuildMemberAdd: 'guildMemberAdd';
GuildMemberRemove: 'guildMemberRemove';
GuildMemberUpdate: 'guildMemberUpdate';
GuildMemberAvailable: 'guildMemberAvailable';
GuildMembersChunk: 'guildMembersChunk';
GuildIntegrationsUpdate: 'guildIntegrationsUpdate';
GuildRoleCreate: 'roleCreate';
GuildRoleDelete: 'roleDelete';
InviteCreate: 'inviteCreate';
InviteDelete: 'inviteDelete';
GuildRoleUpdate: 'roleUpdate';
GuildEmojiCreate: 'emojiCreate';
GuildEmojiDelete: 'emojiDelete';
GuildEmojiUpdate: 'emojiUpdate';
GuildBanAdd: 'guildBanAdd';
GuildBanRemove: 'guildBanRemove';
ChannelCreate: 'channelCreate';
ChannelDelete: 'channelDelete';
ChannelUpdate: 'channelUpdate';
ChannelPinsUpdate: 'channelPinsUpdate';
MessageCreate: 'messageCreate';
MessageDelete: 'messageDelete';
MessageUpdate: 'messageUpdate';
MessageBulkDelete: 'messageDeleteBulk';
MessageReactionAdd: 'messageReactionAdd';
MessageReactionRemove: 'messageReactionRemove';
MessageReactionRemoveAll: 'messageReactionRemoveAll';
MessageReactionRemoveEmoji: 'messageReactionRemoveEmoji';
ThreadCreate: 'threadCreate';
ThreadDelete: 'threadDelete';
ThreadUpdate: 'threadUpdate';
ThreadListSync: 'threadListSync';
ThreadMemberUpdate: 'threadMemberUpdate';
ThreadMembersUpdate: 'threadMembersUpdate';
UserUpdate: 'userUpdate';
PresenceUpdate: 'presenceUpdate';
VoiceServerUpdate: 'voiceServerUpdate';
VoiceStateUpdate: 'voiceStateUpdate';
TypingStart: 'typingStart';
WebhooksUpdate: 'webhookUpdate';
InteractionCreate: 'interactionCreate';
Error: 'error';
Warn: 'warn';
Debug: 'debug';
CacheSweep: 'cacheSweep';
ShardDisconnect: 'shardDisconnect';
ShardError: 'shardError';
ShardReconnecting: 'shardReconnecting';
ShardReady: 'shardReady';
ShardResume: 'shardResume';
Invalidated: 'invalidated';
Raw: 'raw';
StageInstanceCreate: 'stageInstanceCreate';
StageInstanceUpdate: 'stageInstanceUpdate';
StageInstanceDelete: 'stageInstanceDelete';
GuildStickerCreate: 'stickerCreate';
GuildStickerDelete: 'stickerDelete';
GuildStickerUpdate: 'stickerUpdate';
GuildScheduledEventCreate: 'guildScheduledEventCreate';
GuildScheduledEventUpdate: 'guildScheduledEventUpdate';
GuildScheduledEventDelete: 'guildScheduledEventDelete';
GuildScheduledEventUserAdd: 'guildScheduledEventUserAdd';
GuildScheduledEventUserRemove: 'guildScheduledEventUserRemove';
};
export enum ShardEvents {
Close = 'close',
Destroyed = 'destroyed',
InvalidSession = 'invalidSession',
Ready = 'ready',
Resumed = 'resumed',
AllReady = 'allReady',
}
export interface ConstantsEvents {
CLIENT_READY: 'ready';
GUILD_CREATE: 'guildCreate';
GUILD_DELETE: 'guildDelete';
GUILD_UPDATE: 'guildUpdate';
INVITE_CREATE: 'inviteCreate';
INVITE_DELETE: 'inviteDelete';
GUILD_UNAVAILABLE: 'guildUnavailable';
GUILD_MEMBER_ADD: 'guildMemberAdd';
GUILD_MEMBER_REMOVE: 'guildMemberRemove';
GUILD_MEMBER_UPDATE: 'guildMemberUpdate';
GUILD_MEMBER_AVAILABLE: 'guildMemberAvailable';
GUILD_MEMBERS_CHUNK: 'guildMembersChunk';
GUILD_INTEGRATIONS_UPDATE: 'guildIntegrationsUpdate';
GUILD_ROLE_CREATE: 'roleCreate';
GUILD_ROLE_DELETE: 'roleDelete';
GUILD_ROLE_UPDATE: 'roleUpdate';
GUILD_EMOJI_CREATE: 'emojiCreate';
GUILD_EMOJI_DELETE: 'emojiDelete';
GUILD_EMOJI_UPDATE: 'emojiUpdate';
GUILD_BAN_ADD: 'guildBanAdd';
GUILD_BAN_REMOVE: 'guildBanRemove';
CHANNEL_CREATE: 'channelCreate';
CHANNEL_DELETE: 'channelDelete';
CHANNEL_UPDATE: 'channelUpdate';
CHANNEL_PINS_UPDATE: 'channelPinsUpdate';
MESSAGE_CREATE: 'messageCreate';
MESSAGE_DELETE: 'messageDelete';
MESSAGE_UPDATE: 'messageUpdate';
MESSAGE_BULK_DELETE: 'messageDeleteBulk';
MESSAGE_REACTION_ADD: 'messageReactionAdd';
MESSAGE_REACTION_REMOVE: 'messageReactionRemove';
MESSAGE_REACTION_REMOVE_ALL: 'messageReactionRemoveAll';
MESSAGE_REACTION_REMOVE_EMOJI: 'messageReactionRemoveEmoji';
THREAD_CREATE: 'threadCreate';
THREAD_DELETE: 'threadDelete';
THREAD_UPDATE: 'threadUpdate';
THREAD_LIST_SYNC: 'threadListSync';
THREAD_MEMBER_UPDATE: 'threadMemberUpdate';
THREAD_MEMBERS_UPDATE: 'threadMembersUpdate';
USER_UPDATE: 'userUpdate';
PRESENCE_UPDATE: 'presenceUpdate';
VOICE_SERVER_UPDATE: 'voiceServerUpdate';
VOICE_STATE_UPDATE: 'voiceStateUpdate';
TYPING_START: 'typingStart';
WEBHOOKS_UPDATE: 'webhookUpdate';
INTERACTION_CREATE: 'interactionCreate';
ERROR: 'error';
WARN: 'warn';
DEBUG: 'debug';
CACHE_SWEEP: 'cacheSweep';
SHARD_DISCONNECT: 'shardDisconnect';
SHARD_ERROR: 'shardError';
SHARD_RECONNECTING: 'shardReconnecting';
SHARD_READY: 'shardReady';
SHARD_RESUME: 'shardResume';
INVALIDATED: 'invalidated';
RAW: 'raw';
STAGE_INSTANCE_CREATE: 'stageInstanceCreate';
STAGE_INSTANCE_UPDATE: 'stageInstanceUpdate';
STAGE_INSTANCE_DELETE: 'stageInstanceDelete';
GUILD_STICKER_CREATE: 'stickerCreate';
GUILD_STICKER_DELETE: 'stickerDelete';
GUILD_STICKER_UPDATE: 'stickerUpdate';
GUILD_SCHEDULED_EVENT_CREATE: 'guildScheduledEventCreate';
GUILD_SCHEDULED_EVENT_UPDATE: 'guildScheduledEventUpdate';
GUILD_SCHEDULED_EVENT_DELETE: 'guildScheduledEventDelete';
GUILD_SCHEDULED_EVENT_USER_ADD: 'guildScheduledEventUserAdd';
GUILD_SCHEDULED_EVENT_USER_REMOVE: 'guildScheduledEventUserRemove';
}
export interface ConstantsOpcodes {
DISPATCH: 0;
HEARTBEAT: 1;
IDENTIFY: 2;
STATUS_UPDATE: 3;
VOICE_STATE_UPDATE: 4;
VOICE_GUILD_PING: 5;
RESUME: 6;
RECONNECT: 7;
REQUEST_GUILD_MEMBERS: 8;
INVALID_SESSION: 9;
HELLO: 10;
HEARTBEAT_ACK: 11;
}
export interface ConstantsShardEvents {
CLOSE: 'close';
DESTROYED: 'destroyed';
INVALID_SESSION: 'invalidSession';
READY: 'ready';
RESUMED: 'resumed';
}
export interface ConstantsStatus {
READY: 0;
CONNECTING: 1;
RECONNECTING: 2;
IDLE: 3;
NEARLY: 4;
DISCONNECTED: 5;
export enum Status {
Ready = 0,
Connecting = 1,
Reconnecting = 2,
Idle = 3,
Nearly = 4,
Disconnected = 5,
}
export interface CreateGuildScheduledEventInviteURLOptions extends CreateInviteOptions {
@@ -4869,7 +4850,7 @@ export interface StartThreadOptions {
rateLimitPerUser?: number;
}
export type Status = number;
export type ClientStatus = number;
export type StickerResolvable = Sticker | Snowflake;
@@ -5170,6 +5151,7 @@ export {
GuildNSFWLevel,
GuildPremiumTier,
GatewayIntentBits,
GatewayOpcodes,
GuildScheduledEventEntityType,
GuildScheduledEventPrivacyLevel,
GuildScheduledEventStatus,

View File

@@ -39,7 +39,6 @@ import {
CommandInteractionOption,
CommandInteractionOptionResolver,
CommandOptionNonChoiceResolvableType,
Constants,
ContextMenuCommandInteraction,
DMChannel,
Guild,
@@ -98,6 +97,9 @@ import {
ActionRowComponent,
InteractionResponseFields,
ThreadChannelType,
Events,
ShardEvents,
Status,
} from '.';
import { expectAssignable, expectDeprecated, expectNotAssignable, expectNotType, expectType } from 'tsd';
import { Embed } from '@discordjs/builders';
@@ -854,10 +856,9 @@ reactionCollector.on('dispose', (...args) => {
// Make sure the properties are typed correctly, and that no backwards properties
// (K -> V and V -> K) exist:
expectType<'messageCreate'>(Constants.Events.MESSAGE_CREATE);
expectType<'close'>(Constants.ShardEvents.CLOSE);
expectType<1>(Constants.Status.CONNECTING);
expectType<0>(Constants.Opcodes.DISPATCH);
expectAssignable<'messageCreate'>(Events.MessageCreate);
expectAssignable<'close'>(ShardEvents.Close);
expectAssignable<1>(Status.Connecting);
declare const applicationCommandData: ApplicationCommandData;
declare const applicationCommandResolvable: ApplicationCommandResolvable;