Skip to content

Commit 0bb2204

Browse files
author
Vitor
authored
refactor: separate MESSAGE_CREATE fields from APIMessage object (#434)
BREAKING CHANGE: Certain fields that come only through the gateway are now correctly typed as such
1 parent 292c6b5 commit 0bb2204

File tree

8 files changed

+156
-80
lines changed

8 files changed

+156
-80
lines changed

deno/gateway/v10.ts

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ export type GatewayMessageCreateDispatch = DataPayload<
11251125
/**
11261126
* https://discord.com/developers/docs/topics/gateway#message-create
11271127
*/
1128-
export type GatewayMessageCreateDispatchData = APIMessage;
1128+
export type GatewayMessageCreateDispatchData = Omit<APIMessage, 'mentions'> & GatewayMessageEventExtraFields;
11291129

11301130
/**
11311131
* https://discord.com/developers/docs/topics/gateway#message-update
@@ -1138,10 +1138,43 @@ export type GatewayMessageUpdateDispatch = DataPayload<
11381138
/**
11391139
* https://discord.com/developers/docs/topics/gateway#message-update
11401140
*/
1141-
export type GatewayMessageUpdateDispatchData = {
1142-
id: Snowflake;
1143-
channel_id: Snowflake;
1144-
} & Partial<APIMessage>;
1141+
export type GatewayMessageUpdateDispatchData = Omit<Partial<APIMessage>, 'mentions'> &
1142+
GatewayMessageEventExtraFields & {
1143+
/**
1144+
* ID of the message
1145+
*/
1146+
id: Snowflake;
1147+
/**
1148+
* ID of the channel the message was sent in
1149+
*/
1150+
channel_id: Snowflake;
1151+
};
1152+
1153+
export interface GatewayMessageEventExtraFields {
1154+
/**
1155+
* ID of the guild the message was sent in
1156+
*/
1157+
guild_id?: Snowflake;
1158+
/**
1159+
* Member properties for this message's author
1160+
*
1161+
* The member object exists in `MESSAGE_CREATE` and `MESSAGE_UPDATE` events
1162+
* from text-based guild channels
1163+
*
1164+
* See https://discord.com/developers/docs/resources/guild#guild-member-object
1165+
*/
1166+
member?: APIGuildMember;
1167+
/**
1168+
* Users specifically mentioned in the message
1169+
*
1170+
* The `member` field is only present in `MESSAGE_CREATE` and `MESSAGE_UPDATE` events
1171+
* from text-based guild channels
1172+
*
1173+
* See https://discord.com/developers/docs/resources/user#user-object
1174+
* See https://discord.com/developers/docs/resources/guild#guild-member-object
1175+
*/
1176+
mentions: (APIUser & { member?: Omit<APIGuildMember, 'user'> })[];
1177+
}
11451178

11461179
/**
11471180
* https://discord.com/developers/docs/topics/gateway#message-delete

deno/gateway/v9.ts

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ export type GatewayMessageCreateDispatch = DataPayload<
11241124
/**
11251125
* https://discord.com/developers/docs/topics/gateway#message-create
11261126
*/
1127-
export type GatewayMessageCreateDispatchData = APIMessage;
1127+
export type GatewayMessageCreateDispatchData = Omit<APIMessage, 'mentions'> & GatewayMessageEventExtraFields;
11281128

11291129
/**
11301130
* https://discord.com/developers/docs/topics/gateway#message-update
@@ -1137,10 +1137,43 @@ export type GatewayMessageUpdateDispatch = DataPayload<
11371137
/**
11381138
* https://discord.com/developers/docs/topics/gateway#message-update
11391139
*/
1140-
export type GatewayMessageUpdateDispatchData = {
1141-
id: Snowflake;
1142-
channel_id: Snowflake;
1143-
} & Partial<APIMessage>;
1140+
export type GatewayMessageUpdateDispatchData = Omit<Partial<APIMessage>, 'mentions'> &
1141+
GatewayMessageEventExtraFields & {
1142+
/**
1143+
* ID of the message
1144+
*/
1145+
id: Snowflake;
1146+
/**
1147+
* ID of the channel the message was sent in
1148+
*/
1149+
channel_id: Snowflake;
1150+
};
1151+
1152+
export interface GatewayMessageEventExtraFields {
1153+
/**
1154+
* ID of the guild the message was sent in
1155+
*/
1156+
guild_id?: Snowflake;
1157+
/**
1158+
* Member properties for this message's author
1159+
*
1160+
* The member object exists in `MESSAGE_CREATE` and `MESSAGE_UPDATE` events
1161+
* from text-based guild channels
1162+
*
1163+
* See https://discord.com/developers/docs/resources/guild#guild-member-object
1164+
*/
1165+
member?: APIGuildMember;
1166+
/**
1167+
* Users specifically mentioned in the message
1168+
*
1169+
* The `member` field is only present in `MESSAGE_CREATE` and `MESSAGE_UPDATE` events
1170+
* from text-based guild channels
1171+
*
1172+
* See https://discord.com/developers/docs/resources/user#user-object
1173+
* See https://discord.com/developers/docs/resources/guild#guild-member-object
1174+
*/
1175+
mentions: (APIUser & { member?: Omit<APIGuildMember, 'user'> })[];
1176+
}
11441177

11451178
/**
11461179
* https://discord.com/developers/docs/topics/gateway#message-delete

deno/payloads/v10/channel.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import type { APIApplication } from './application.ts';
66
import type { APIPartialEmoji } from './emoji.ts';
7-
import type { APIGuildMember } from './guild.ts';
87
import type { APIMessageInteraction } from './interactions.ts';
98
import type { APIRole } from './permissions.ts';
109
import type { APISticker, APIStickerItem } from './sticker.ts';
@@ -326,10 +325,6 @@ export interface APIMessage {
326325
* ID of the channel the message was sent in
327326
*/
328327
channel_id: Snowflake;
329-
/**
330-
* ID of the guild the message was sent in
331-
*/
332-
guild_id?: Snowflake;
333328
/**
334329
* The author of this message (only a valid user in the case where the message is generated by a user or bot user)
335330
*
@@ -339,15 +334,6 @@ export interface APIMessage {
339334
* See https://discord.com/developers/docs/resources/user#user-object
340335
*/
341336
author: APIUser;
342-
/**
343-
* Member properties for this message's author
344-
*
345-
* The member object exists in `MESSAGE_CREATE` and `MESSAGE_UPDATE` events
346-
* from text-based guild channels
347-
*
348-
* See https://discord.com/developers/docs/resources/guild#guild-member-object
349-
*/
350-
member?: APIGuildMember;
351337
/**
352338
* Contents of the message
353339
*/
@@ -377,7 +363,7 @@ export interface APIMessage {
377363
* See https://discord.com/developers/docs/resources/user#user-object
378364
* See https://discord.com/developers/docs/resources/guild#guild-member-object
379365
*/
380-
mentions: (APIUser & { member?: Omit<APIGuildMember, 'user'> })[];
366+
mentions: APIUser[];
381367
/**
382368
* Roles specifically mentioned in this message
383369
*

deno/payloads/v9/channel.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import type { APIApplication } from './application.ts';
66
import type { APIPartialEmoji } from './emoji.ts';
7-
import type { APIGuildMember } from './guild.ts';
87
import type { APIMessageInteraction } from './interactions.ts';
98
import type { APIRole } from './permissions.ts';
109
import type { APISticker, APIStickerItem } from './sticker.ts';
@@ -326,10 +325,6 @@ export interface APIMessage {
326325
* ID of the channel the message was sent in
327326
*/
328327
channel_id: Snowflake;
329-
/**
330-
* ID of the guild the message was sent in
331-
*/
332-
guild_id?: Snowflake;
333328
/**
334329
* The author of this message (only a valid user in the case where the message is generated by a user or bot user)
335330
*
@@ -339,15 +334,6 @@ export interface APIMessage {
339334
* See https://discord.com/developers/docs/resources/user#user-object
340335
*/
341336
author: APIUser;
342-
/**
343-
* Member properties for this message's author
344-
*
345-
* The member object exists in `MESSAGE_CREATE` and `MESSAGE_UPDATE` events
346-
* from text-based guild channels
347-
*
348-
* See https://discord.com/developers/docs/resources/guild#guild-member-object
349-
*/
350-
member?: APIGuildMember;
351337
/**
352338
* Contents of the message
353339
*/
@@ -377,7 +363,7 @@ export interface APIMessage {
377363
* See https://discord.com/developers/docs/resources/user#user-object
378364
* See https://discord.com/developers/docs/resources/guild#guild-member-object
379365
*/
380-
mentions: (APIUser & { member?: Omit<APIGuildMember, 'user'> })[];
366+
mentions: APIUser[];
381367
/**
382368
* Roles specifically mentioned in this message
383369
*

gateway/v10.ts

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ export type GatewayMessageCreateDispatch = DataPayload<
11251125
/**
11261126
* https://discord.com/developers/docs/topics/gateway#message-create
11271127
*/
1128-
export type GatewayMessageCreateDispatchData = APIMessage;
1128+
export type GatewayMessageCreateDispatchData = Omit<APIMessage, 'mentions'> & GatewayMessageEventExtraFields;
11291129

11301130
/**
11311131
* https://discord.com/developers/docs/topics/gateway#message-update
@@ -1138,10 +1138,43 @@ export type GatewayMessageUpdateDispatch = DataPayload<
11381138
/**
11391139
* https://discord.com/developers/docs/topics/gateway#message-update
11401140
*/
1141-
export type GatewayMessageUpdateDispatchData = {
1142-
id: Snowflake;
1143-
channel_id: Snowflake;
1144-
} & Partial<APIMessage>;
1141+
export type GatewayMessageUpdateDispatchData = Omit<Partial<APIMessage>, 'mentions'> &
1142+
GatewayMessageEventExtraFields & {
1143+
/**
1144+
* ID of the message
1145+
*/
1146+
id: Snowflake;
1147+
/**
1148+
* ID of the channel the message was sent in
1149+
*/
1150+
channel_id: Snowflake;
1151+
};
1152+
1153+
export interface GatewayMessageEventExtraFields {
1154+
/**
1155+
* ID of the guild the message was sent in
1156+
*/
1157+
guild_id?: Snowflake;
1158+
/**
1159+
* Member properties for this message's author
1160+
*
1161+
* The member object exists in `MESSAGE_CREATE` and `MESSAGE_UPDATE` events
1162+
* from text-based guild channels
1163+
*
1164+
* See https://discord.com/developers/docs/resources/guild#guild-member-object
1165+
*/
1166+
member?: APIGuildMember;
1167+
/**
1168+
* Users specifically mentioned in the message
1169+
*
1170+
* The `member` field is only present in `MESSAGE_CREATE` and `MESSAGE_UPDATE` events
1171+
* from text-based guild channels
1172+
*
1173+
* See https://discord.com/developers/docs/resources/user#user-object
1174+
* See https://discord.com/developers/docs/resources/guild#guild-member-object
1175+
*/
1176+
mentions: (APIUser & { member?: Omit<APIGuildMember, 'user'> })[];
1177+
}
11451178

11461179
/**
11471180
* https://discord.com/developers/docs/topics/gateway#message-delete

gateway/v9.ts

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ export type GatewayMessageCreateDispatch = DataPayload<
11241124
/**
11251125
* https://discord.com/developers/docs/topics/gateway#message-create
11261126
*/
1127-
export type GatewayMessageCreateDispatchData = APIMessage;
1127+
export type GatewayMessageCreateDispatchData = Omit<APIMessage, 'mentions'> & GatewayMessageEventExtraFields;
11281128

11291129
/**
11301130
* https://discord.com/developers/docs/topics/gateway#message-update
@@ -1137,10 +1137,43 @@ export type GatewayMessageUpdateDispatch = DataPayload<
11371137
/**
11381138
* https://discord.com/developers/docs/topics/gateway#message-update
11391139
*/
1140-
export type GatewayMessageUpdateDispatchData = {
1141-
id: Snowflake;
1142-
channel_id: Snowflake;
1143-
} & Partial<APIMessage>;
1140+
export type GatewayMessageUpdateDispatchData = Omit<Partial<APIMessage>, 'mentions'> &
1141+
GatewayMessageEventExtraFields & {
1142+
/**
1143+
* ID of the message
1144+
*/
1145+
id: Snowflake;
1146+
/**
1147+
* ID of the channel the message was sent in
1148+
*/
1149+
channel_id: Snowflake;
1150+
};
1151+
1152+
export interface GatewayMessageEventExtraFields {
1153+
/**
1154+
* ID of the guild the message was sent in
1155+
*/
1156+
guild_id?: Snowflake;
1157+
/**
1158+
* Member properties for this message's author
1159+
*
1160+
* The member object exists in `MESSAGE_CREATE` and `MESSAGE_UPDATE` events
1161+
* from text-based guild channels
1162+
*
1163+
* See https://discord.com/developers/docs/resources/guild#guild-member-object
1164+
*/
1165+
member?: APIGuildMember;
1166+
/**
1167+
* Users specifically mentioned in the message
1168+
*
1169+
* The `member` field is only present in `MESSAGE_CREATE` and `MESSAGE_UPDATE` events
1170+
* from text-based guild channels
1171+
*
1172+
* See https://discord.com/developers/docs/resources/user#user-object
1173+
* See https://discord.com/developers/docs/resources/guild#guild-member-object
1174+
*/
1175+
mentions: (APIUser & { member?: Omit<APIGuildMember, 'user'> })[];
1176+
}
11441177

11451178
/**
11461179
* https://discord.com/developers/docs/topics/gateway#message-delete

payloads/v10/channel.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import type { APIApplication } from './application';
66
import type { APIPartialEmoji } from './emoji';
7-
import type { APIGuildMember } from './guild';
87
import type { APIMessageInteraction } from './interactions';
98
import type { APIRole } from './permissions';
109
import type { APISticker, APIStickerItem } from './sticker';
@@ -326,10 +325,6 @@ export interface APIMessage {
326325
* ID of the channel the message was sent in
327326
*/
328327
channel_id: Snowflake;
329-
/**
330-
* ID of the guild the message was sent in
331-
*/
332-
guild_id?: Snowflake;
333328
/**
334329
* The author of this message (only a valid user in the case where the message is generated by a user or bot user)
335330
*
@@ -339,15 +334,6 @@ export interface APIMessage {
339334
* See https://discord.com/developers/docs/resources/user#user-object
340335
*/
341336
author: APIUser;
342-
/**
343-
* Member properties for this message's author
344-
*
345-
* The member object exists in `MESSAGE_CREATE` and `MESSAGE_UPDATE` events
346-
* from text-based guild channels
347-
*
348-
* See https://discord.com/developers/docs/resources/guild#guild-member-object
349-
*/
350-
member?: APIGuildMember;
351337
/**
352338
* Contents of the message
353339
*/
@@ -377,7 +363,7 @@ export interface APIMessage {
377363
* See https://discord.com/developers/docs/resources/user#user-object
378364
* See https://discord.com/developers/docs/resources/guild#guild-member-object
379365
*/
380-
mentions: (APIUser & { member?: Omit<APIGuildMember, 'user'> })[];
366+
mentions: APIUser[];
381367
/**
382368
* Roles specifically mentioned in this message
383369
*

0 commit comments

Comments
 (0)