From d08d3d015e6d8bfc2641458d5b7fcf7d12f8ca43 Mon Sep 17 00:00:00 2001 From: almeidx Date: Fri, 14 Apr 2023 23:37:58 +0100 Subject: [PATCH 1/2] feat(Attachment): voice messages --- .../discord.js/src/structures/Attachment.js | 20 +++++++++++++++++++ packages/discord.js/typings/index.d.ts | 2 ++ 2 files changed, 22 insertions(+) diff --git a/packages/discord.js/src/structures/Attachment.js b/packages/discord.js/src/structures/Attachment.js index 11a45643194e..2cb75cdf7f11 100644 --- a/packages/discord.js/src/structures/Attachment.js +++ b/packages/discord.js/src/structures/Attachment.js @@ -99,6 +99,26 @@ class Attachment { * @type {boolean} */ this.ephemeral = data.ephemeral ?? false; + + if ('duration_secs' in data) { + /** + * The duration of this attachment in seconds (if an audio) + * @type {?number} + */ + this.duration = data.duration_secs; + } else { + this.duration ??= null; + } + + if ('waveform' in data) { + /** + * The base64 encoded bytearray representing a sampled waveform (if an audio) + * @type {?string} + */ + this.waveform = data.waveform; + } else { + this.waveform ??= null; + } } /** diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 47f500f7e5c1..957168b26125 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -2014,6 +2014,7 @@ export class Attachment { private attachment: BufferResolvable | Stream; public contentType: string | null; public description: string | null; + public duration: number | null; public ephemeral: boolean; public height: number | null; public id: Snowflake; @@ -2022,6 +2023,7 @@ export class Attachment { public size: number; public get spoiler(): boolean; public url: string; + public waveform: string | null; public width: number | null; public toJSON(): unknown; } From 6d539463dbbd58f5dd6430432ffb0636ad929460 Mon Sep 17 00:00:00 2001 From: Almeida Date: Wed, 19 Apr 2023 18:35:07 +0100 Subject: [PATCH 2/2] docs: requested changes Co-authored-by: Tetie --- packages/discord.js/src/structures/Attachment.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/discord.js/src/structures/Attachment.js b/packages/discord.js/src/structures/Attachment.js index 2cb75cdf7f11..086d7a870731 100644 --- a/packages/discord.js/src/structures/Attachment.js +++ b/packages/discord.js/src/structures/Attachment.js @@ -102,7 +102,8 @@ class Attachment { if ('duration_secs' in data) { /** - * The duration of this attachment in seconds (if an audio) + * The duration of this attachment in seconds + * This will only be available if the attachment is an audio file. * @type {?number} */ this.duration = data.duration_secs; @@ -112,7 +113,8 @@ class Attachment { if ('waveform' in data) { /** - * The base64 encoded bytearray representing a sampled waveform (if an audio) + * The base64 encoded byte array representing a sampled waveform + * This will only be available if the attachment is an audio file. * @type {?string} */ this.waveform = data.waveform;