diff --git a/src/structures/MessageAttachment.js b/src/structures/MessageAttachment.js index 6bac7a70a520..1fef93f17c2a 100644 --- a/src/structures/MessageAttachment.js +++ b/src/structures/MessageAttachment.js @@ -43,6 +43,24 @@ class MessageAttachment { return this; } + /** + * Sets whether this attachment is a spoiler + * @param {boolean} [spoiler=true] Whether the attachment should be marked as a spoiler + * @returns {MessageAttachment} This attachment + */ + setSpoiler(spoiler = true) { + if (spoiler === this.spoiler) return this; + + if (!spoiler) { + while (this.spoiler) { + this.name.slice('SPOILER_'.length); + } + return this; + } + this.name = `SPOILER_${this.name}`; + return this; + } + _patch(data) { /** * The attachment's id @@ -93,7 +111,7 @@ class MessageAttachment { * @readonly */ get spoiler() { - return Util.basename(this.url).startsWith('SPOILER_'); + return Util.basename(this.url ?? this.name).startsWith('SPOILER_'); } toJSON() { diff --git a/typings/index.d.ts b/typings/index.d.ts index 0488c8165ad3..724c4901e0c0 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1210,6 +1210,7 @@ export class MessageAttachment { public width: number | null; public setFile(attachment: BufferResolvable | Stream, name?: string): this; public setName(name: string): this; + public setSpoiler(spoiler?: boolean): this; public toJSON(): unknown; }