From 627511d6522f772b84c25e6a3f6da06b06bb912e Mon Sep 17 00:00:00 2001 From: Ben <88249114+BenjammingKirby@users.noreply.github.com> Date: Wed, 14 Dec 2022 16:35:40 -0500 Subject: [PATCH] feat(InteractionResponse): createdTimestamp (#8917) * feat(InteractionResponse): createdTimestamp * feat(InteractionResponse): createdTimestamp * Apply suggestions from code review Co-authored-by: MrMythicalYT <91077061+MrMythicalYT@users.noreply.github.com> Co-authored-by: MrMythicalYT <91077061+MrMythicalYT@users.noreply.github.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../src/structures/InteractionResponse.js | 19 +++++++++++++++++++ packages/discord.js/typings/index.d.ts | 2 ++ 2 files changed, 21 insertions(+) diff --git a/packages/discord.js/src/structures/InteractionResponse.js b/packages/discord.js/src/structures/InteractionResponse.js index b99f80f69..3c1114c9e 100644 --- a/packages/discord.js/src/structures/InteractionResponse.js +++ b/packages/discord.js/src/structures/InteractionResponse.js @@ -1,5 +1,6 @@ 'use strict'; +const { DiscordSnowflake } = require('@sapphire/snowflake'); const { InteractionType } = require('discord-api-types/v10'); const { DiscordjsError, ErrorCodes } = require('../errors'); @@ -21,6 +22,24 @@ class InteractionResponse { this.client = interaction.client; } + /** + * The timestamp the interaction response was created at + * @type {number} + * @readonly + */ + get createdTimestamp() { + return DiscordSnowflake.timestampFrom(this.id); + } + + /** + * The time the interaction response was created at + * @type {Date} + * @readonly + */ + get createdAt() { + return new Date(this.createdTimestamp); + } + /** * Collects a single component interaction that passes the filter. * The Promise will reject if the time expires. diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 192eef711..d0a5ed97e 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -555,6 +555,8 @@ export class InteractionResponse { public interaction: Interaction>; public client: Client; public id: Snowflake; + public get createdAt(): Date; + public get createdTimestamp(): number; public awaitMessageComponent( options?: AwaitMessageCollectorOptionsParams, ): Promise[T]>;