Skip to content

feat(Attachment): voice messages #9392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/discord.js/src/structures/Attachment.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,28 @@ class Attachment {
* @type {boolean}
*/
this.ephemeral = data.ephemeral ?? false;

if ('duration_secs' in data) {
/**
* The duration of this attachment in seconds
* <info>This will only be available if the attachment is an audio file.</info>
* @type {?number}
*/
this.duration = data.duration_secs;
} else {
this.duration ??= null;
}

if ('waveform' in data) {
/**
* The base64 encoded byte array representing a sampled waveform
* <info>This will only be available if the attachment is an audio file.</info>
* @type {?string}
*/
this.waveform = data.waveform;
} else {
this.waveform ??= null;
}
}

/**
Expand Down
2 changes: 2 additions & 0 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down