Unknown interaction

Hey! This is a bit of a weird issue, the code that wraps my dropdowns is quite difficult to pick apart on the backend to be able to post here, but this is what's in the active bit, should be relatively easy to understand.
this.eventLengthDropdown = this.cache.storage.registerDropdown("eventLengthDropdown:" + this.id, async (cache: Cache, interaction: AnySelectMenuInteraction) => {
if (interaction.values[0] === "-1") {
await interaction.showModal(this.getLengthModal());
return;
}

if (!interaction.values[0]) return;

interaction.deferUpdate().catch(err => cache.handleError(err, true));
this.data.length = parseInt(interaction.values[0]);
this.update();
});

private getLengthModal() {
const modal = new ModalBuilder()
.setCustomId("schedulingEventEditLengthModal:" + this.id)
.setTitle("Edit Length");

modal.addComponents(
new ActionRowBuilder<ModalActionRowComponentBuilder>().addComponents(new TextInputBuilder()
.setCustomId("length")
.setLabel("Length (in mins)")
.setRequired(true)
.setValue(this.data.length.toString())
.setStyle(TextInputStyle.Short))
);

return modal;
}
this.eventLengthDropdown = this.cache.storage.registerDropdown("eventLengthDropdown:" + this.id, async (cache: Cache, interaction: AnySelectMenuInteraction) => {
if (interaction.values[0] === "-1") {
await interaction.showModal(this.getLengthModal());
return;
}

if (!interaction.values[0]) return;

interaction.deferUpdate().catch(err => cache.handleError(err, true));
this.data.length = parseInt(interaction.values[0]);
this.update();
});

private getLengthModal() {
const modal = new ModalBuilder()
.setCustomId("schedulingEventEditLengthModal:" + this.id)
.setTitle("Edit Length");

modal.addComponents(
new ActionRowBuilder<ModalActionRowComponentBuilder>().addComponents(new TextInputBuilder()
.setCustomId("length")
.setLabel("Length (in mins)")
.setRequired(true)
.setValue(this.data.length.toString())
.setStyle(TextInputStyle.Short))
);

return modal;
}
The intention here is that the dropdown has various values (15, 30, 45, 60, 90, 120, -1). If the value is -1, then it's supposed to show a modal in response, however about 70% of the time (not all the time), it gives me an "Unknown interaction" error. This does not happen when the values[0] is not -1. Does anyone know why showing the modal gives an unknown interaction? If there's any explanations to various parts you need, let me know. Djs: 14.8.0
8 Replies
d.js toolkit
d.js toolkitā€¢2mo 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!
d.js docs
d.js docsā€¢2mo ago
Common causes of DiscordAPIError[10062]: Unknown interaction: - Initial response took more than 3 seconds āžž defer the response *. - Wrong interaction object inside a collector. - Two processes handling the same command (the first consumes the interaction, so it won't be valid for the other instance) * Note: you cannot defer modal or autocomplete value responses
treble/luna
treble/lunaā€¢2mo ago
Also update djs
brokenrecord388
brokenrecord388OPā€¢2mo ago
well this is what I originally thought, there's definitely only one handler for this specific one so it can't be the third, if the non -1's are working it can't be the second, which leaves the first, which could possibly indicate that for some reason getLengthModal is taking a while to create. How do you defer a response if when you deferUpdate it says the interaction has already been acknowledged?
brokenrecord388
brokenrecord388OPā€¢2mo ago
No description
brokenrecord388
brokenrecord388OPā€¢2mo ago
this.data is an object, example:
public data: {
length: number,
type: EventType,
date: Date,
note: string | undefined,
ownerTextOverride: string | undefined;
typeTextOverride: string | undefined;
colorOverride: HexColorString | undefined;
};
public data: {
length: number,
type: EventType,
date: Date,
note: string | undefined,
ownerTextOverride: string | undefined;
typeTextOverride: string | undefined;
colorOverride: HexColorString | undefined;
};
in this case, length is any number let me just try moving getLengthModal into a static variable I mean that's what I thought, let me get you the event, all the register method is doing is listing the customid on an object array for the event listener
export default class SelectMenu implements DiscordEvent {
public name = Events.InteractionCreate
async execute(cache: Cache, data: any[]) {
const interaction: Interaction = data[0];
if (!interaction) return;
if (!interaction.isAnySelectMenu()) return;

var dropdown = cache.storage.dropdowns[interaction.customId];
if (!dropdown) {
for (const drop in cache.storage.dropdowns) {
if (!drop.includes("*")) continue;
const regex = new RegExp("^" + drop.split("*").map((str: string) => str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1")).join(".*") + "$");
if (regex.test(interaction.customId)) {
const subdrop = cache.storage.registerDropdown(interaction.customId);
dropdown = subdrop;
break;
}
}
}
if (dropdown) {
if (dropdown.authorOnly && interaction.user.id !== dropdown.author) {
interaction.reply({ embeds: [
Messages.Error(cache, "This is not your dropdown to use!")
], ephemeral: true })
return;
}

dropdown.setValue(interaction.user.id, interaction.values);
if (dropdown.execute) {
dropdown.execute(cache, interaction);
}
}

if (interaction.replied || interaction.deferred) return;
await interaction.deferUpdate().catch(err => cache.handleError(err, true));
}
};
export default class SelectMenu implements DiscordEvent {
public name = Events.InteractionCreate
async execute(cache: Cache, data: any[]) {
const interaction: Interaction = data[0];
if (!interaction) return;
if (!interaction.isAnySelectMenu()) return;

var dropdown = cache.storage.dropdowns[interaction.customId];
if (!dropdown) {
for (const drop in cache.storage.dropdowns) {
if (!drop.includes("*")) continue;
const regex = new RegExp("^" + drop.split("*").map((str: string) => str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1")).join(".*") + "$");
if (regex.test(interaction.customId)) {
const subdrop = cache.storage.registerDropdown(interaction.customId);
dropdown = subdrop;
break;
}
}
}
if (dropdown) {
if (dropdown.authorOnly && interaction.user.id !== dropdown.author) {
interaction.reply({ embeds: [
Messages.Error(cache, "This is not your dropdown to use!")
], ephemeral: true })
return;
}

dropdown.setValue(interaction.user.id, interaction.values);
if (dropdown.execute) {
dropdown.execute(cache, interaction);
}
}

if (interaction.replied || interaction.deferred) return;
await interaction.deferUpdate().catch(err => cache.handleError(err, true));
}
};
(this is just a wrapper-ish thing that is auto-registered to client.on etc) that catch prints the error when it detects one, I took it off showModal just so it wouldn't go through my error handler that handler just adds some āœØ pazazz āœØ honestly I don't know the difference between let and var etc, don't tell the developers hm ok is there an ezpz dumb dumb explanation or is it just an avoid
brokenrecord388
brokenrecord388OPā€¢2mo ago
so
{
var stinky = "poopyhead";
let stonky = "thingy";
}

console.log(stinky); //print "poopyhead"
console.log(stonky); //stonky missing
{
var stinky = "poopyhead";
let stonky = "thingy";
}

console.log(stinky); //print "poopyhead"
console.log(stonky); //stonky missing
etc? you were right, I didn't notice the true that silences the error, the deferUpdate is erroring too šŸ™‚ šŸ¤¦ also I've just found the issue by accident, it's this part:
if (interaction.replied || interaction.deferred) return;
await interaction.deferUpdate().catch(err => cache.handleError(err, true));
if (interaction.replied || interaction.deferred) return;
await interaction.deferUpdate().catch(err => cache.handleError(err, true));
didn't notice it on the look through, that bit was put there on the assumption I was always going to be deferUpdate'ing, removing this bit fixes it I did but it still did it, possibly me being a bonehead in that department and restarting the bot too quickly, I've left it commented out for now, the only reason it's there is cause my lazy ass keeps forgetting to defer my dropdowns my understanding of await was just that it held the thread until it was done, what would that do to impove that bit since thats just updating internal variables? oh okay, thanks šŸ™‚
Want results from more Discord servers?
Add your server