From 65eace40462cae4f0ed4a1220e73b6c01ef5b9b1 Mon Sep 17 00:00:00 2001 From: Helloyunho Date: Fri, 25 Dec 2020 22:09:29 +0900 Subject: [PATCH] Update message and textchannel --- src/structures/message.ts | 26 +++++++++++++++++++++----- src/structures/textChannel.ts | 17 +++++++++-------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/structures/message.ts b/src/structures/message.ts index d8e6325..a0b2ae8 100644 --- a/src/structures/message.ts +++ b/src/structures/message.ts @@ -108,21 +108,37 @@ export class Message extends Base { } /** Edits this message. */ - async edit(text?: string, option?: MessageOption): Promise { + async edit( + content?: string | AllMessageOptions, + option?: AllMessageOptions + ): Promise { + if (typeof content === 'object') { + option = content + content = undefined + } + if (content === undefined && option === undefined) { + throw new Error('Either text or option is necessary.') + } + if (option instanceof Embed) { + option = { + embed: option + } + } if ( this.client.user !== undefined && this.author.id !== this.client.user?.id - ) + ) { throw new Error("Cannot edit other users' messages") - return this.channel.editMessage(this.id, text, option) + } + return this.channel.editMessage(this.id, content, option) } /** Creates a Reply to this Message. */ async reply( - text?: string | AllMessageOptions, + content?: string | AllMessageOptions, option?: AllMessageOptions ): Promise { - return this.channel.send(text, option, this) + return this.channel.send(content, option, this) } /** Deletes the Message. */ diff --git a/src/structures/textChannel.ts b/src/structures/textChannel.ts index 699b4ad..ec137e5 100644 --- a/src/structures/textChannel.ts +++ b/src/structures/textChannel.ts @@ -41,29 +41,30 @@ export class TextChannel extends Channel { /** * - * @param text Text content of the Message to send. + * @param content Text content of the Message to send. * @param option Various other Message options. * @param reply Reference to a Message object to reply-to. */ async send( - text?: string | AllMessageOptions, + content?: string | AllMessageOptions, option?: AllMessageOptions, reply?: Message ): Promise { - if (typeof text === 'object') { - option = text - text = undefined + if (typeof content === 'object') { + option = content + content = undefined } - if (text === undefined && option === undefined) { + if (content === undefined && option === undefined) { throw new Error('Either text or option is necessary.') } - if (option instanceof Embed) + if (option instanceof Embed) { option = { embed: option } + } const payload: any = { - content: text, + content: content, embed: option?.embed, file: option?.file, tts: option?.tts,