Skip to content

Commit

Permalink
fix: always create new empty arrays (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranet authored Nov 24, 2021
1 parent 9564927 commit 406dd08
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export async function reply(message: Message, options: string | ReplyMessageOpti
}

function resolvePayload(target: MessageTarget, options: string | Options, extra?: Options | undefined): Promise<MessagePayload> {
options = typeof options === 'string' ? { content: options, ...unsetValues } : { content: null, ...unsetValues, ...options };
options =
typeof options === 'string' ? { content: options, embeds: [], attachments: [] } : { content: null, embeds: [], attachments: [], ...options };
return MessagePayload.create(target, options, extra).resolveData().resolveFiles();
}

Expand All @@ -78,11 +79,3 @@ async function sendPayload(message: Message, payload: MessagePayload): Promise<M
}

type Options = MessageOptions | WebhookMessageOptions;

// This variable is casted like this (instead of `unsetValues: Options`) because `attachments` is a property on
// `MessageEditOptions`, therefore it does not exist in `MessageOptions`. This makes the property non-assignable, and so
// it can't be inlined with the other object spreads.
//
// As a workaround, I just define this object somewhere so we don't re-create it on each call. It is then casted to the
// valid type. This way TypeScript is happy.
const unsetValues = { embeds: [], attachments: [] } as Options;

0 comments on commit 406dd08

Please sign in to comment.