feat: sessionId

This commit is contained in:
Elysia 2024-01-26 20:30:07 +07:00
parent 5962c59684
commit e8c2b967c3
6 changed files with 15 additions and 6 deletions

View File

@ -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`);

View File

@ -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],

View File

@ -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,

View File

@ -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,

View File

@ -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,

1
typings/index.d.ts vendored
View File

@ -791,6 +791,7 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
public presences: PresenceManager;
public billing: BillingManager;
public settings: ClientUserSettingManager;
public readonly sessionId: If<Ready, string, undefined>;
public destroy(): void;
public fetchGuildPreview(guild: GuildResolvable): Promise<GuildPreview>;
public fetchInvite(invite: InviteResolvable, options?: ClientFetchInviteOptions): Promise<Invite>;