mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 04:23:31 +01:00
feat(MessageAttachment): allow files to be marked as spoilers (#6509)
Co-authored-by: Antonio Román <kyradiscord@gmail.com>
This commit is contained in:
@@ -43,6 +43,24 @@ class MessageAttachment {
|
|||||||
return this;
|
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) {
|
_patch(data) {
|
||||||
/**
|
/**
|
||||||
* The attachment's id
|
* The attachment's id
|
||||||
@@ -93,7 +111,7 @@ class MessageAttachment {
|
|||||||
* @readonly
|
* @readonly
|
||||||
*/
|
*/
|
||||||
get spoiler() {
|
get spoiler() {
|
||||||
return Util.basename(this.url).startsWith('SPOILER_');
|
return Util.basename(this.url ?? this.name).startsWith('SPOILER_');
|
||||||
}
|
}
|
||||||
|
|
||||||
toJSON() {
|
toJSON() {
|
||||||
|
|||||||
1
typings/index.d.ts
vendored
1
typings/index.d.ts
vendored
@@ -1210,6 +1210,7 @@ export class MessageAttachment {
|
|||||||
public width: number | null;
|
public width: number | null;
|
||||||
public setFile(attachment: BufferResolvable | Stream, name?: string): this;
|
public setFile(attachment: BufferResolvable | Stream, name?: string): this;
|
||||||
public setName(name: string): this;
|
public setName(name: string): this;
|
||||||
|
public setSpoiler(spoiler?: boolean): this;
|
||||||
public toJSON(): unknown;
|
public toJSON(): unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user