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 toolkit2mo 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
SerqeevichOP2mo 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);
}
});
Inky
Inky2mo ago
It’s just a warning, but the warning is correct
Serqeevich
SerqeevichOP2mo 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.
Inky
Inky2mo ago
Since ur only using it to make a collector, use withResponse instead Are you sure you aren’t using fetchReply elsewhere?
Serqeevich
SerqeevichOP2mo ago
its dont work
Inky
Inky2mo 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
SerqeevichOP2mo 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);

};

});


};

};
Inky
Inky2mo ago
You don’t have any other command?
Serqeevich
SerqeevichOP2mo ago
have
Inky
Inky2mo ago
It’s easier just to use the project-wide search bar if on VSC
Serqeevich
SerqeevichOP2mo ago
I don't understand how this could be related, but yes, I don't use it anywhere
No description
Serqeevich
SerqeevichOP2mo 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
Inky
Inky2mo ago
Can you run the bot with the trace-deprecation flag? i.e. node --trace-deprecation index.js
Serqeevich
SerqeevichOP2mo ago
nothing
Serqeevich
SerqeevichOP2mo ago
No description
Serqeevich
SerqeevichOP2mo ago
stop sorry it's without fetchREply
Inky
Inky2mo ago
Warning went away?
Serqeevich
SerqeevichOP2mo 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
SerqeevichOP2mo ago
No description
Inky
Inky2mo ago
Is there an error?
Serqeevich
SerqeevichOP2mo 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'
Inky
Inky2mo ago
Actually, just don’t enable anything
Serqeevich
SerqeevichOP2mo ago
?
Inky
Inky2mo ago
!
Serqeevich
SerqeevichOP2mo ago
This is pointless advice
Inky
Inky2mo ago
How? That’s just how the reply method behaves InteractionResponse is only returned when you don’t enable withResponse and withReply
NyR
NyR2mo ago
Well yeah, because it's not a method on InteractionCallbackResponse, do <response>.resources!.message!.createMessageComponentCollector
Inky
Inky2mo 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
SerqeevichOP2mo ago
Thank you!!! :emoji_52:

Did you find this page helpful?