Skip to content

Commit

Permalink
refactor: make ownerID nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
imnaiyar committed Sep 19, 2024
1 parent c48d8f5 commit aceb5b3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
3 changes: 2 additions & 1 deletion packages/discord.js/src/errors/Messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ const Messages = {
[DjsErrorCodes.ChannelNotCached]: 'Could not find the channel where this message came from in the cache!',
[DjsErrorCodes.StageChannelResolve]: 'Could not resolve channel to a stage channel.',
[DjsErrorCodes.GuildScheduledEventResolve]: 'Could not resolve the guild scheduled event.',
[DjsErrorCodes.FetchOwnerId]: type => `Couldn't resolve the ${type} ownerId to fetch the ${type} member.`,
[DjsErrorCodes.FetchOwnerId]: type =>
`Couldn't resolve the ${type} ownerId to fetch the ${type} ${type === 'group DM' ? 'owner' : 'member'}.`,

[DjsErrorCodes.InvalidType]: (name, expected, an = false) => `Supplied ${name} is not a${an ? 'n' : ''} ${expected}.`,
[DjsErrorCodes.InvalidElement]: (type, name, elem) => `Supplied ${type} ${name} includes an invalid element: ${elem}`,
Expand Down
18 changes: 13 additions & 5 deletions packages/discord.js/src/structures/PartialGroupDMChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@ class PartialGroupDMChannel extends BaseChannel {
*/
this.messages = new PartialGroupDMMessageManager(this);

/**
* The user id of the owner of this Group DM Channel
* @type {Snowflake}
*/
this.ownerId = data.owner_id;
if ('owner_id' in data) {
/**
* The user id of the owner of this Group DM Channel
* @type {?Snowflake}
*/
this.ownerId = data.owner_id;
} else {
this.ownerId ??= null;
}
}

/**
Expand All @@ -67,6 +71,10 @@ class PartialGroupDMChannel extends BaseChannel {
* @returns {Promise<User>}
*/
async fetchOwner(options) {
if (!this.ownerId) {
throw new DiscordjsError(ErrorCodes.FetchOwnerId, 'group DM');
}

return this.client.users.fetch(this.ownerId, options);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2558,7 +2558,7 @@ export class PartialGroupDMChannel extends BaseChannel {
public icon: string | null;
public recipients: PartialRecipient[];
public messages: PartialGroupDMMessageManager;
public ownerId: Snowflake;
public ownerId: Snowflake | null;
public iconURL(options?: ImageURLOptions): string | null;
public fetchOwner(options?: BaseFetchOptions): Promise<User>;
public toString(): ChannelMention;
Expand Down

0 comments on commit aceb5b3

Please sign in to comment.