Update message and textchannel

This commit is contained in:
Helloyunho 2020-12-25 22:09:29 +09:00
parent 3695b81de6
commit 65eace4046
2 changed files with 30 additions and 13 deletions

View file

@ -108,21 +108,37 @@ export class Message extends Base {
}
/** Edits this message. */
async edit(text?: string, option?: MessageOption): Promise<Message> {
async edit(
content?: string | AllMessageOptions,
option?: AllMessageOptions
): Promise<Message> {
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<Message> {
return this.channel.send(text, option, this)
return this.channel.send(content, option, this)
}
/** Deletes the Message. */

View file

@ -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<Message> {
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,