How to properly use "fetchReply" in Discord.js Interaction API?

While working on my Discord.js bot, I encountered the following warning: -# (node:12684) Warning: Supplying "fetchReply" for interaction response options is deprecated. Utilize "withResponse" instead or fetch the response after using the method.
30 Replies
d.js toolkit
d.js toolkit5d ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Serqeevich
SerqeevichOP5d ago
I’m using fetchReply: true to fetch the interaction response message, as shown in the example below and its work
const response = await interaction.reply({
fetchReply: true,
flags: [MessageFlags.Ephemeral],
components: [row],
});

const collector = response.createMessageComponentCollector({
componentType: ComponentType.StringSelect,
time: 60_000,
filter: (i: AnySelectMenuInteraction) => i.user.id === interaction.user.id && i.customId === selectMenu.data.custom_id,
});

collector.on('collect', async (i: AnySelectMenuInteraction) => {
const memberIds = i.values;

for (const memberId of memberIds) {
console.log(memberId);
}
});
const response = await interaction.reply({
fetchReply: true,
flags: [MessageFlags.Ephemeral],
components: [row],
});

const collector = response.createMessageComponentCollector({
componentType: ComponentType.StringSelect,
time: 60_000,
filter: (i: AnySelectMenuInteraction) => i.user.id === interaction.user.id && i.customId === selectMenu.data.custom_id,
});

collector.on('collect', async (i: AnySelectMenuInteraction) => {
const memberIds = i.values;

for (const memberId of memberIds) {
console.log(memberId);
}
});
Kinect3000
Kinect30005d ago
It’s just a warning, but the warning is correct
Serqeevich
SerqeevichOP5d ago
I’ve tried replacing fetchReply with withResponse or fetching the reply after calling interaction.reply() as suggested in the warning, but neither approach works.
Kinect3000
Kinect30005d ago
Since ur only using it to make a collector, use withResponse instead Are you sure you aren’t using fetchReply elsewhere?
Serqeevich
SerqeevichOP5d ago
its dont work
Kinect3000
Kinect30005d ago
Are you sure you aren’t using fetchReply elsewhere? The warning shows any time you use fetchReply for the first time when running the code
Serqeevich
SerqeevichOP5d ago
sure
import { ActionRowBuilder, AnySelectMenuInteraction, ButtonInteraction, ComponentType, MessageFlags, PermissionFlagsBits, StringSelectMenuBuilder, StringSelectMenuOptionBuilder } from "discord.js";
import CustomClient from "../../../base/classes/Client";
import { ButtonIds } from "../../../base/enums/buttonsIds.enum";
import IComponent from "../../../base/interfaces/component.interface";
import { Emojis } from "../../../base/enums/emojis.enum";

export default class Kick implements IComponent {

client: CustomClient;

constructor(client: CustomClient) {
this.client = client;
}

id = ButtonIds.Kick;

async execute(interaction: ButtonInteraction, client: CustomClient) {

const validation = await client.voiceMasterHelper.validation(interaction, this.id);

if (!validation.success) {

if (validation.message) {

interaction.reply({
content: validation.message,
flags: MessageFlags.Ephemeral
});

};

return;

};

const data = validation.data;
const channel = validation.channel!;
const membersSize = channel?.members.size;

const options: StringSelectMenuOptionBuilder[] = channel.members
.filter((m) => m.id !== data?.owner_id)
.filter((m) => !m.permissions.has(PermissionFlagsBits.Administrator || PermissionFlagsBits.ModerateMembers))
.map((m) => {
return new StringSelectMenuOptionBuilder()
.setLabel(`${m.user.username}`)
.setValue(`${m.user.id}`)
});


if (options.length === 0) {

await interaction.reply({
content: `<:warn:${Emojis.Warn}> _Вам некого исключать из канала._`,
flags: MessageFlags.Ephemeral
});

return

};

const selectMenu = new StringSelectMenuBuilder()
.setCustomId(`kick_members`)
.setMinValues(1)
.setMaxValues(membersSize - 1)
.setOptions(options)


const row = new ActionRowBuilder<StringSelectMenuBuilder>()
.setComponents(selectMenu)

const response = await interaction.reply({
components: [row],
flags: MessageFlags.Ephemeral,
// withResponse: true,
})

const collector = response.createMessageComponentCollector({
componentType: ComponentType.StringSelect,
time: 60_000,
filter: (i: AnySelectMenuInteraction) => i.user.id === interaction.user.id && i.customId === selectMenu.data.custom_id,
})


collector.on(`collect`, async (i: AnySelectMenuInteraction) => {

const memberIds = i.values;

for (const memberId of memberIds) {

console.log(memberId);

};

});


};

};
import { ActionRowBuilder, AnySelectMenuInteraction, ButtonInteraction, ComponentType, MessageFlags, PermissionFlagsBits, StringSelectMenuBuilder, StringSelectMenuOptionBuilder } from "discord.js";
import CustomClient from "../../../base/classes/Client";
import { ButtonIds } from "../../../base/enums/buttonsIds.enum";
import IComponent from "../../../base/interfaces/component.interface";
import { Emojis } from "../../../base/enums/emojis.enum";

export default class Kick implements IComponent {

client: CustomClient;

constructor(client: CustomClient) {
this.client = client;
}

id = ButtonIds.Kick;

async execute(interaction: ButtonInteraction, client: CustomClient) {

const validation = await client.voiceMasterHelper.validation(interaction, this.id);

if (!validation.success) {

if (validation.message) {

interaction.reply({
content: validation.message,
flags: MessageFlags.Ephemeral
});

};

return;

};

const data = validation.data;
const channel = validation.channel!;
const membersSize = channel?.members.size;

const options: StringSelectMenuOptionBuilder[] = channel.members
.filter((m) => m.id !== data?.owner_id)
.filter((m) => !m.permissions.has(PermissionFlagsBits.Administrator || PermissionFlagsBits.ModerateMembers))
.map((m) => {
return new StringSelectMenuOptionBuilder()
.setLabel(`${m.user.username}`)
.setValue(`${m.user.id}`)
});


if (options.length === 0) {

await interaction.reply({
content: `<:warn:${Emojis.Warn}> _Вам некого исключать из канала._`,
flags: MessageFlags.Ephemeral
});

return

};

const selectMenu = new StringSelectMenuBuilder()
.setCustomId(`kick_members`)
.setMinValues(1)
.setMaxValues(membersSize - 1)
.setOptions(options)


const row = new ActionRowBuilder<StringSelectMenuBuilder>()
.setComponents(selectMenu)

const response = await interaction.reply({
components: [row],
flags: MessageFlags.Ephemeral,
// withResponse: true,
})

const collector = response.createMessageComponentCollector({
componentType: ComponentType.StringSelect,
time: 60_000,
filter: (i: AnySelectMenuInteraction) => i.user.id === interaction.user.id && i.customId === selectMenu.data.custom_id,
})


collector.on(`collect`, async (i: AnySelectMenuInteraction) => {

const memberIds = i.values;

for (const memberId of memberIds) {

console.log(memberId);

};

});


};

};
Kinect3000
Kinect30005d ago
You don’t have any other command?
Serqeevich
SerqeevichOP5d ago
have
Kinect3000
Kinect30005d ago
It’s easier just to use the project-wide search bar if on VSC
Serqeevich
SerqeevichOP5d ago
I don't understand how this could be related, but yes, I don't use it anywhere
No description
Serqeevich
SerqeevichOP5d ago
const response = await interaction.reply({
components: [row],
flags: MessageFlags.Ephemeral,
withResponse: true,
})

const collector = response.createMessageComponentCollector({
componentType: ComponentType.StringSelect,
time: 60_000,
filter: (i: AnySelectMenuInteraction) => i.user.id === interaction.user.id && i.customId === selectMenu.data.custom_id,
})


collector.on(`collect`, async (i: AnySelectMenuInteraction) => {

const memberIds = i.values;

for (const memberId of memberIds) {

console.log(memberId);

};

});
const response = await interaction.reply({
components: [row],
flags: MessageFlags.Ephemeral,
withResponse: true,
})

const collector = response.createMessageComponentCollector({
componentType: ComponentType.StringSelect,
time: 60_000,
filter: (i: AnySelectMenuInteraction) => i.user.id === interaction.user.id && i.customId === selectMenu.data.custom_id,
})


collector.on(`collect`, async (i: AnySelectMenuInteraction) => {

const memberIds = i.values;

for (const memberId of memberIds) {

console.log(memberId);

};

});
if i use withResponse: true - my collector doesn't work if i change withResponse on fetchReply - i see id in console
Kinect3000
Kinect30005d ago
Can you run the bot with the trace-deprecation flag? i.e. node --trace-deprecation index.js
Serqeevich
SerqeevichOP5d ago
nothing
Serqeevich
SerqeevichOP5d ago
No description
Serqeevich
SerqeevichOP5d ago
stop sorry it's without fetchREply
Kinect3000
Kinect30005d ago
Warning went away?
Serqeevich
SerqeevichOP5d ago
strange but yes, but it doesn't matter, the problem is not in the warning but in the fact that the code does not work
Serqeevich
SerqeevichOP5d ago
No description
Kinect3000
Kinect30005d ago
Is there an error?
Serqeevich
SerqeevichOP5d ago
no ok when i use withResponse i get InteractionCallbackResponse and fetchReply return message and if i use withResponse i get an error with method createMessageComponentCollector Property 'createMessageComponentCollector' does not exist on type 'InteractionCallbackResponse'
Kinect3000
Kinect30005d ago
Actually, just don’t enable anything
Serqeevich
SerqeevichOP5d ago
?
Kinect3000
Kinect30005d ago
!
Serqeevich
SerqeevichOP5d ago
This is pointless advice
Kinect3000
Kinect30005d ago
How? That’s just how the reply method behaves InteractionResponse is only returned when you don’t enable withResponse and withReply
NyR
NyR5d ago
Well yeah, because it's not a method on InteractionCallbackResponse, do <response>.resources!.message!.createMessageComponentCollector
Kinect3000
Kinect30005d ago
Not that you needed fetchReply in the first place Unless you were on a much older version that had fetchReply, but didn’t return anything w/o fetchReply
Serqeevich
SerqeevichOP5d ago
Thank you!!! :emoji_52:

Did you find this page helpful?