From e8c2b967c384208fc2627d0dd44847819aab1ff8 Mon Sep 17 00:00:00 2001 From: Elysia <71698422+aiko-chan-ai@users.noreply.github.com> Date: Fri, 26 Jan 2024 20:30:07 +0700 Subject: [PATCH] feat: sessionId --- src/client/Client.js | 10 +++++++++- src/structures/Message.js | 4 ++-- src/structures/MessagePayload.js | 2 +- src/structures/Modal.js | 2 +- src/structures/interfaces/TextBasedChannel.js | 2 +- typings/index.d.ts | 1 + 6 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/client/Client.js b/src/client/Client.js index fd66005..11c7b1c 100644 --- a/src/client/Client.js +++ b/src/client/Client.js @@ -507,6 +507,14 @@ class Client extends BaseClient { }); } + /** + * The current session id of the shard + * @type {?string} + */ + get sessionId() { + return this.ws.shards.first()?.sessionId; + } + /** * Options for {@link Client#acceptInvite}. * @typedef {Object} AcceptInviteOptions @@ -539,7 +547,7 @@ class Client extends BaseClient { const data = await this.api.invites(code).post({ DiscordContext: { location: 'Markdown Link' }, data: { - session_id: this.ws.shards.first()?.sessionId, + session_id: this.sessionId, }, }); this.emit(Events.DEBUG, `[Invite > Guild ${i.guild?.id}] Joined`); diff --git a/src/structures/Message.js b/src/structures/Message.js index e1c376c..f11d4c1 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -1025,7 +1025,7 @@ class Message extends Base { channel_id: this.channelId, message_id: this.id, application_id: this.applicationId ?? this.author.id, - session_id: this.client.ws.shards.first()?.sessionId, + session_id: this.client.sessionId, message_flags: this.flags.bitfield, data: { component_type: MessageComponentTypes.BUTTON, @@ -1124,7 +1124,7 @@ class Message extends Base { channel_id: this.channelId, message_id: this.id, application_id: this.applicationId ?? this.author.id, - session_id: this.client.ws.shards.first()?.sessionId, + session_id: this.client.sessionId, message_flags: this.flags.bitfield, data: { component_type: MessageComponentTypes[selectMenu.type], diff --git a/src/structures/MessagePayload.js b/src/structures/MessagePayload.js index 37d09c5..14e524c 100644 --- a/src/structures/MessagePayload.js +++ b/src/structures/MessagePayload.js @@ -205,7 +205,7 @@ class MessagePayload { this.options.activity.type ) { const type = ActivityFlags.resolve(this.options.activity.type); - const sessionId = this.target.client.ws.shards.first()?.sessionId; + const sessionId = this.target.client.sessionId; const partyId = this.options.activity.partyId; activity = { type, diff --git a/src/structures/Modal.js b/src/structures/Modal.js index 47226c4..9d76c86 100644 --- a/src/structures/Modal.js +++ b/src/structures/Modal.js @@ -132,7 +132,7 @@ class Modal { channel_id: this.channelId, data: dataFinal, nonce, - session_id: this.client.ws.shards.first()?.sessionId, + session_id: this.client.sessionId, }; this.client.api.interactions.post({ data: postData, diff --git a/src/structures/interfaces/TextBasedChannel.js b/src/structures/interfaces/TextBasedChannel.js index e88c6aa..3673a90 100644 --- a/src/structures/interfaces/TextBasedChannel.js +++ b/src/structures/interfaces/TextBasedChannel.js @@ -703,7 +703,7 @@ function createPostData( application_id: applicationId, guild_id: guildId, channel_id: channelId, - session_id: client.ws.shards.first()?.sessionId, + session_id: client.sessionId, data: { version: commandVersion, id: commandId, diff --git a/typings/index.d.ts b/typings/index.d.ts index 77dbc88..77a7ebd 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -791,6 +791,7 @@ export class Client extends BaseClient { public presences: PresenceManager; public billing: BillingManager; public settings: ClientUserSettingManager; + public readonly sessionId: If; public destroy(): void; public fetchGuildPreview(guild: GuildResolvable): Promise; public fetchInvite(invite: InviteResolvable, options?: ClientFetchInviteOptions): Promise;