k.yrK
Convex Communityβ€’3y agoβ€’
7 replies
k.yr

Discord Bot - Issues responding to interactions

Hello πŸ‘‹
I can't seem to get my Convex endpoint to respond to my interactions and I have no idea why. Going by the below code any interaction should be met with a message response of Blah however, I just get an empty response (shown in attached image).

const discordRoute = httpAction(async (ctx, request) => {
  console.log("Received request");
  const { isValid, interaction } = await verifyDiscordRequest(request);

  console.log("Is request valid", isValid);

  if (!isValid || !interaction)
    return new Response("Bad request signature.", { status: 401 });

  if (interaction.type === InteractionType.Ping)
    return new Response(
      JSON.stringify({
        type: InteractionResponseType.Pong,
      }),
      { status: 200 },
    );

  console.log("Got here");
  console.log("interaction type", interaction.type);

  if (interaction.type === InteractionType.ApplicationCommand) {
    return new Response(
      JSON.stringify({
        type: InteractionResponseType.ChannelMessageWithSource,
        data: { content: "Blah" },
      }),
      { headers: { "Content-Type": "application/json" }, status: 200 },
    );
  }
  return new Response("Unknown request", { status: 500 });
});

http.route({
  path: "/discord",
  method: "POST",
  handler: discordRoute,
});


My log output looks like,

'Received request'
log
'Is request valid' true
log
'Got here'
log
'interaction type' 2


I cannot see any issues with my Discord bot permissions either. Any help would be much appreciated!
Screenshot_2023-09-24_at_3.31.30_pm.png
Was this page helpful?