Skip to content

Commit

Permalink
refactor: fix for discordjs 14.16.2 partialgroupdm typings
Browse files Browse the repository at this point in the history
  • Loading branch information
favna committed Sep 19, 2024
1 parent 843f700 commit 000fc16
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
type MessageCreateOptions,
type MessageEditOptions,
type MessageReplyOptions,
type PartialGroupDMChannel,
type ReplyOptions
} from 'discord.js';

Expand Down Expand Up @@ -70,7 +71,7 @@ async function handle<T extends MessageOptions>(message: Message, options: strin

const payloadOptions = existing ? resolveEditPayload(existing, options as MessageEditOptions) : resolveSendPayload<T>(options);
const payload = await MessagePayload.create(message.channel, payloadOptions, extra).resolveBody().resolveFiles();
const response = await (existing ? tryEdit(message, existing, payload) : message.channel.send(payload));
const response = await (existing ? tryEdit(message, existing, payload) : trySend(message, payload));
track(message, response);

return response;
Expand Down Expand Up @@ -107,6 +108,10 @@ async function tryEdit(message: Message, response: Message, payload: MessagePayl
// We always call `track()` right after `tryEdit()`, so it'll be tracked
// once the message has been sent, provided it did not throw.
free(message);
return message.channel.send(payload);
return trySend(message, payload);
}
}

async function trySend(message: Message, payload: MessagePayload) {
return (message.channel as Exclude<Message['channel'], PartialGroupDMChannel>).send(payload);
}

0 comments on commit 000fc16

Please sign in to comment.