Cannot edit interaction after modal input

Ok so here is my problem, I want to achieve something like so: Step 1: send interaction with button Step 2: user clicks button Step 3: modal shows and user enters stuff Step 4: after submit edit the original interaction Problem is, editReply() and updateMessage() doesn't let me do that (replying to the modal works) and discord api returns with a "Unknown Webhook" error:
DiscordAPIError[10015]: Unknown Webhook
// i cut this part off to save word count
at async Client.<anonymous> (C:\Users\mt\Visual Studio Code\testBot\handler.js:93:17) {
requestBody: {
files: undefined,
json: { content: '', embeds: [Array], components: [Array] }
},
rawError: { message: 'Unknown Webhook', code: 10015 },
code: 10015,
status: 404,
method: 'PATCH',
url: 'https://discord.com/api/v10/webhooks/bleh/bleh/messages/@original'
}
DiscordAPIError[10015]: Unknown Webhook
// i cut this part off to save word count
at async Client.<anonymous> (C:\Users\mt\Visual Studio Code\testBot\handler.js:93:17) {
requestBody: {
files: undefined,
json: { content: '', embeds: [Array], components: [Array] }
},
rawError: { message: 'Unknown Webhook', code: 10015 },
code: 10015,
status: 404,
method: 'PATCH',
url: 'https://discord.com/api/v10/webhooks/bleh/bleh/messages/@original'
}
Is there a way to achieve step 4 as defined?
23 Replies
d.js toolkit
d.js toolkitβ€’15mo 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! - βœ… Marked as resolved by OP
ShompiFlen
ShompiFlenβ€’15mo ago
there is definitely a way to do what you want, but show your code what is your approach at the moment
aa battery
aa batteryOPβ€’15mo ago
so first i had this for the button
if (interaction.data.custom_id === "cookieButton") {
await api.interactions.createModal(interaction.id, interaction.token, loginEmbeds.cookieModal);
}
if (interaction.data.custom_id === "cookieButton") {
await api.interactions.createModal(interaction.id, interaction.token, loginEmbeds.cookieModal);
}
then my approach for step 4
if (interaction.data.custom_id === "cookieMenu") {
// yada yada
await api.interactions.editReply(interaction.id, interaction.token, { content: "", embeds: [loginEmbeds.moreThanOneUid], components: [selectActionRow]});
return;
}
if (interaction.data.custom_id === "cookieMenu") {
// yada yada
await api.interactions.editReply(interaction.id, interaction.token, { content: "", embeds: [loginEmbeds.moreThanOneUid], components: [selectActionRow]});
return;
}
the code fails at editReply or updateMessage (they produce the same outcome)
ShompiFlen
ShompiFlenβ€’15mo ago
why are you using api are you even using discord.js structures?
aa battery
aa batteryOPβ€’15mo ago
bro idk it works ig i just used the example from the docs (@discordjs) https://discord.js.org/docs/packages/core/main
discord.js
discord.js
discord.js is a powerful Node.js module that allows you to interact with the Discord API very easily. It takes a much more object-oriented approach than most other JS Discord libraries, making your bot's code significantly tidier and easier to comprehend.
ShompiFlen
ShompiFlenβ€’15mo ago
ah you are using core
aa battery
aa batteryOPβ€’15mo ago
im not sure what you mean yes i used the @discordjs mainly cause the code looks better
ShompiFlen
ShompiFlenβ€’15mo ago
well i dont really use core so i dont really know how to help sorry about that
aa battery
aa batteryOPβ€’15mo ago
i see how would you do it normally tho cause v14 -> core is easily translatable
ShompiFlen
ShompiFlenβ€’15mo ago
with an awaitModalSubmition
aa battery
aa batteryOPβ€’15mo ago
ah i see
ShompiFlen
ShompiFlenβ€’15mo ago
once you receive the modal you proceed to update the message
aa battery
aa batteryOPβ€’15mo ago
ah alright thank you for that ill see if i can find a solution
ShompiFlen
ShompiFlenβ€’15mo ago
but also i think the error suggests that the interaction token expired... which interaction are you trying to update? and how long is it taking?
aa battery
aa batteryOPβ€’15mo ago
relatively 2s ish what i was trying to do was just do 4 api requests to a game server then respond accordingly normal reply works and it goes out just fine so it rules out token expiration
ShompiFlen
ShompiFlenβ€’15mo ago
so in which step of the execution is this failing?
aa battery
aa batteryOPβ€’15mo ago
the editReply() which i think is because the interaction object is not the message but the modal interaction i see my mistake. but then my issue at the core is to update the message that the modal is triggered on, which i'm unable to sorry so do you mean the code that triggers the modal? oh wait i also had a mistake with my explanation earlier updateMessage() does the same thing as reply() theres only one difference that is discord app says that it replies to the command for updateMessage() and replies to (previous) message for reply() but yeah none of them do the thing i wanted it to do (which is to update the original message)
aa battery
aa batteryOPβ€’15mo ago
yeah thats what i thought as well but here was what happened so that button triggers the modal then the user enters stuff and updateMessage() created the second message as you can see
No description
aa battery
aa batteryOPβ€’15mo ago
so basically i use followUp() instead?
async runModal(interaction, api) {
if (interaction.data.custom_id === "cookieMenu") {
const AMERICA = new StringSelectMenuOptionBuilder({ label: "American server", value: "1", emoji: { id: undefined, name: "πŸ‡ΊπŸ‡Έ" } });
const EUROPE = new StringSelectMenuOptionBuilder({ label: "Europian server", value: "2", emoji: { id: undefined, name: "πŸ‡ͺπŸ‡Ί" } });
const ASIA = new StringSelectMenuOptionBuilder({ label: "Asian server", value: "3", emoji: { id: undefined, name: "🏳️" } });
const CHT = new StringSelectMenuOptionBuilder({ label: "HW/TW/MO server", value: "4", emoji: { id: undefined, name: "πŸ‘Ž" } });

const cookieString = interaction.data.components[0].components[0].value;

const uids = await initialiser.getUids(cookieString);

if (uids.length > 1) {
var selectActionRow = loginEmbeds.serverField;
for (const item of uids) {
switch (item.region) {
case "os_usa":
selectActionRow.components[0].addOptions(AMERICA);
break;
case "os_euro":
selectActionRow.components[0].addOptions(EUROPE);
break;
case "os_asia":
selectActionRow.components[0].addOptions(ASIA);
break;
case "os_cht":
selectActionRow.components[0].addOptions(CHT);
}
}
await api.interactions.reply(interaction.id, interaction.token, { content: "", embeds: [loginEmbeds.moreThanOneUid], components: [selectActionRow]});
return;
}
async runModal(interaction, api) {
if (interaction.data.custom_id === "cookieMenu") {
const AMERICA = new StringSelectMenuOptionBuilder({ label: "American server", value: "1", emoji: { id: undefined, name: "πŸ‡ΊπŸ‡Έ" } });
const EUROPE = new StringSelectMenuOptionBuilder({ label: "Europian server", value: "2", emoji: { id: undefined, name: "πŸ‡ͺπŸ‡Ί" } });
const ASIA = new StringSelectMenuOptionBuilder({ label: "Asian server", value: "3", emoji: { id: undefined, name: "🏳️" } });
const CHT = new StringSelectMenuOptionBuilder({ label: "HW/TW/MO server", value: "4", emoji: { id: undefined, name: "πŸ‘Ž" } });

const cookieString = interaction.data.components[0].components[0].value;

const uids = await initialiser.getUids(cookieString);

if (uids.length > 1) {
var selectActionRow = loginEmbeds.serverField;
for (const item of uids) {
switch (item.region) {
case "os_usa":
selectActionRow.components[0].addOptions(AMERICA);
break;
case "os_euro":
selectActionRow.components[0].addOptions(EUROPE);
break;
case "os_asia":
selectActionRow.components[0].addOptions(ASIA);
break;
case "os_cht":
selectActionRow.components[0].addOptions(CHT);
}
}
await api.interactions.reply(interaction.id, interaction.token, { content: "", embeds: [loginEmbeds.moreThanOneUid], components: [selectActionRow]});
return;
}
the important stuff is at the end i see, so what should i do? no thats where i handled the submission this is the modal sending part
if (interaction.data.custom_id === "cookieButton") {
await api.interactions.createModal(interaction.id, interaction.token, loginEmbeds.cookieModal);
}
if (interaction.data.custom_id === "cookieButton") {
await api.interactions.createModal(interaction.id, interaction.token, loginEmbeds.cookieModal);
}
oh wait that was supposd to be updateMessage i changed that to uh test some stuff but same thing happens anyway alright wait a min
aa battery
aa batteryOPβ€’15mo ago
Ok im sorry again for my mistake earlier updateMessage does work but in a very weird way so I'm not really sure what is happening so basically when I use UpdateMessage it does work. Once. afterwards if i do the same thing, it will give me a "Invalid Form Body" error. i removed all the code thats making requests and just sent the embed with the selector on its own to see if the wait to request stuff is causing issues but the same thing happened.
No description
No description
aa battery
aa batteryOPβ€’15mo ago
here, sorry for wait
No description
aa battery
aa batteryOPβ€’15mo ago
oh so what i do is i first do a let selectActionRow then i do whatever with it?
No description
aa battery
aa batteryOPβ€’15mo ago
but then i cant modify a const.... OH RIGHT omg i did not realise that im so sorry in the end it was some problems with the classes for embeds i was using as well as that so thank u very much
Want results from more Discord servers?
Add your server