I have a discord bot that presents the user with a number of modals reachable through buttons in an embedded message. This has been working for weeks without issue.
Suddenly all of the modals throw a generic “Something went wrong. Try again.” when the user tries to submit them. No code changes have been pushed. I’ve tried running the bot on different hardware and have the same issue. The error message appears in <2 seconds and the rest of the bot is responsive. I have a console log that prints when the modal is presented to the user and when the user pushes the Submit button. The server running the bot only ever sees the first console log so the response doesn’t seem to be making it back to the server at all. Code below:
export async function execute(
client: ExtendedClient,
interaction: Interaction,
contract: ClaimableAirdrop,
queue: TransactionQueue
): Promise<void> {
const formatDate = (): string => new Date(Date.now()).toUTCString();
const errorChannel = client.channels.cache.get(channels.error) as TextChannel;
try {
console.log("Command called");
// Check if user is on cooldown
const canProceed = await checkAndSetUserCooldown(interaction.user.id);
if (!canProceed) {
if (interaction.isRepliable()) {
await interaction.reply({
content:
"You are on cooldown. Please wait a few seconds before interacting again.",
ephemeral: true,
});
}
return;
}
// Chat Command Interactions
if (interaction.isChatInputCommand()) {
// Defer reply to prevent timeout
await interaction.deferReply({ ephemeral: true });
if (interaction.commandName === "airdrop") {
await mainResponse(interaction, contract);
} else {
// Invalid Chat command passed
await interaction.editReply({
content: "👀 This Command does not exist!",
});
await errorChannel.send(
`[ERROR]n${formatDate()}nInvalid Chat Command PassednBy: ${
interaction.user.username
}`
);
}
} else if (interaction.isButton()) {
// Button Interactions
if (interaction.customId === "find_rewards") {
await addAddressResponse(interaction, contract);
} else if (interaction.customId === "set_chain") {
await setChainResponse(interaction, contract, queue);
} else if (interaction.customId === "set_discord") {
await setDiscordResponse(interaction, contract, queue);
} else if (interaction.customId === "clear_searched") {
await interaction.deferUpdate();
await clearSearchedResponse(interaction, contract);
} else if (interaction.customId === "begin_claim") {
await interaction.deferReply({ ephemeral: true });
await beginClaimResponse(interaction, contract, queue);
} else {
await interaction.reply({
content: "👀 This button is not configured!",
ephemeral: true,
});
await errorChannel.send(
`[ERROR]n${formatDate()}nInvalid Button InteractionnBy: ${
interaction.user.username
}`
);
}
} else if (interaction.isModalSubmit()) {
// Modal Submission Interactions
await interaction.deferReply({ ephemeral: true });
if (interaction.customId === "set_chain_modal") {
await setChainResponse(interaction, contract, queue);
} else if (interaction.customId === "wallet_entry_modal") {
await addAddressResponse(interaction, contract);
} else if (interaction.customId === "set_discord_modal") {
await setDiscordResponse(interaction, contract, queue);
} else {
await interaction.editReply({
content: "👀 This modal is not configured!",
});
await errorChannel.send(
`[ERROR]n${formatDate()}nInvalid Modal SubmissionnBy: ${
interaction.user.username
}`
);
}
} else {
// Different kind of interaction
await errorChannel.send(
`[ERROR]n${formatDate()}nUnknown Interaction TypenBy: ${
interaction.user.username
}`
);
}
} catch (error) {
console.error(`Error Handling Interaction: ${error}`);
await errorChannel.send(`[ERROR]n${formatDate()}nInteraction Handlingn${error}`);
if (interaction.isRepliable()) {
await interaction.editReply({
content: `❌ Error: ${error.message}`,
});
}
}
}
export async function addAddressResponse(
interaction: ModalSubmitInteraction | ButtonInteraction,
contract: ClaimableAirdrop
): Promise<void> {
if (interaction.isButton()) {
try {
console.log(
"Search Address Button Pressed by " +
interaction.user.username +
" - " +
interaction.user.id
);
const modal = await createWalletEntryModal();
await interaction.showModal(modal);
await interaction.deleteReply();
} catch (error) {
console.log(error);
}
} else if (interaction.isModalSubmit()) {
const userId = interaction.user.id;
console.log(
"Search Address Modal Submitted by " + interaction.user.username + " - " + userId
);
...