Discord HTTP Interactions Issue

I'm having this weird issue trying to make a bot with CF workers where my worker hangs on the fetch in this block:
export async function discordFetch(env, url, options) {
    options = options || {};
    url = `https://discord.com/api/v10/${url}`;
    options.headers = {
        ...options.headers || {},
        'Authorization': `Bot ${env.DISCORD_TOKEN}`,
        'User-Agent': 'DiscordBot (https://github.com/SkyKings-Guild/GameNightManager, 1.0)'
    }
    let response;
    try {
        response = await fetch(url, options); // hangs here
    } catch (error) {
        console.error('Error fetching', error);
        throw new HTTPError(null, null, `Error fetching: ${error}`);
    }

The fetch request reaches Discord (it dispatches the defer that I expect it to) but nothing else happens.
Just to add on, I proxied it through my local machine using ngrok, and it worked just fine. It seems like requests coming directly from Discord are causing some sort of issue, but proxying them through my own machine resolves that somehow.

Any ideas on what could be happening?

Some additional code:
router.post('/process', async (request, env) => {
    try {
        const { isValid, interaction } = await server.verifyDiscordRequest(
            request,
            env,
        );
        if (!isValid || !interaction) {
            console.error('Bad request signature.');
            return new Response('Bad request signature.', { status: 401 });
        }

        if (interaction.type === InteractionType.PING) {
            return new JsonResponse({
            type: InteractionResponseType.PONG,
            });
        }

        if (interaction.type === InteractionType.APPLICATION_COMMAND) {
            // Permission Check
            ...
            try {
                // this call hangs with no errors logged
                await createInteractionResponse(env, interaction, {
                    type: InteractionResponseType.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE, 
                    data: {flags: InteractionResponseFlags.EPHEMERAL}
                });
                switch (interaction.data.name.toLowerCase()) {
                    case SET_LIMIT.name.toLowerCase(): {
                        await setLimitCommand(env, interaction);
                        return new Response(null, {status: 202});
                    }
...

export async function createInteractionResponse(env, interaction, data) {
    let fct = await discordFetch(env, `interactions/${interaction.id}/${interaction.token}/callback`, {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
        },
        body: JSON.stringify(data),
    });
    // this doesn't run
    console.log("done")
}

https://github.com/SkyKings-Guild/GameNightManager
image.png
Was this page helpful?