deferReply() with withResponse/fetchReply

const { Client, CommandInteraction } = require("discord.js");
const { QuickDB } = require("quick.db");

const formatUptime = (ms) => {
const d = Math.floor(ms / (1000 * 60 * 60 * 24));
const h = Math.floor((ms / (1000 * 60 * 60)) % 24);
const min = Math.floor((ms / (1000 * 60)) % 60);
const s = Math.floor((ms / 1000) % 60);
return d > 0 ? `${d}j ${h}h` : `${h}h ${min}min ${s}s`;
};

module.exports = {
data: {
description: "Show the bot's latency."
},
/**
*
* @param {Client} client
* @param {QuickDB} db
* @param {CommandInteraction} interaction
*/
exec(client, db, interaction) {
interaction.deferReply({ fetchReply: true }).then((msg) => {
interaction.editReply({
embeds: [{
color: interaction.guild.members.me.displayColor,
title: "🏓 Pong",
fields: [
{
name: "WebSocket",
value: `${client.ws.ping}ms`,
inline: true
},
{
name: "API",
value: `${msg.createdTimestamp - interaction.createdTimestamp}ms`,
inline: true
},
{
name: "Uptime",
value: formatUptime(client.uptime)
}
],
footer: {
text: client.user.username
},
timestamp: new Date().toISOString()
}]
}).catch(() => {});
});
}
};
const { Client, CommandInteraction } = require("discord.js");
const { QuickDB } = require("quick.db");

const formatUptime = (ms) => {
const d = Math.floor(ms / (1000 * 60 * 60 * 24));
const h = Math.floor((ms / (1000 * 60 * 60)) % 24);
const min = Math.floor((ms / (1000 * 60)) % 60);
const s = Math.floor((ms / 1000) % 60);
return d > 0 ? `${d}j ${h}h` : `${h}h ${min}min ${s}s`;
};

module.exports = {
data: {
description: "Show the bot's latency."
},
/**
*
* @param {Client} client
* @param {QuickDB} db
* @param {CommandInteraction} interaction
*/
exec(client, db, interaction) {
interaction.deferReply({ fetchReply: true }).then((msg) => {
interaction.editReply({
embeds: [{
color: interaction.guild.members.me.displayColor,
title: "🏓 Pong",
fields: [
{
name: "WebSocket",
value: `${client.ws.ping}ms`,
inline: true
},
{
name: "API",
value: `${msg.createdTimestamp - interaction.createdTimestamp}ms`,
inline: true
},
{
name: "Uptime",
value: formatUptime(client.uptime)
}
],
footer: {
text: client.user.username
},
timestamp: new Date().toISOString()
}]
}).catch(() => {});
});
}
};
I decided to go back to dev and after updating discord.js, I noticed that fetchReply was decrapted, and when I switch to withResponse, I get NaN for API latency.
5 Replies
d.js toolkit
d.js toolkit5mo ago
d.js docs
d.js docs5mo ago
The fetchReply option when replying to an interaction will be removed in v15.
- {..., fetchReply: true}
+ {..., withResponse: true}
- {..., fetchReply: true}
+ {..., withResponse: true}
This returns an InteractionCallbackResponse Use <InteractionCallbackResponse>.resource.message to get the message
Gamatek
GamatekOP5mo ago
really? msg -> callback.resource.message why do that 😭
- interaction.deferReply({ fetchReply: true }).then((msg) => {
+ interaction.deferReply({ withResponse: true }).then(({ resource: { message: msg } }) => {
- interaction.deferReply({ fetchReply: true }).then((msg) => {
+ interaction.deferReply({ withResponse: true }).then(({ resource: { message: msg } }) => {
okay thx for your help
Amgelo
Amgelo5mo ago
discord didn't have a way to get the new message while replying, so fetchReply was added since it's a useful thing to have, it fetches manually after the reply is done, with a separate api call now recently discord added the withResponse parameter, which actually returns the message in the reply's response, so an extra api call isn't needed anymore but it does change where you get the message since it doesn't return the message directly, it's inside that resource object, hence the change
Gamatek
GamatekOP5mo ago
haaa, okay

Did you find this page helpful?