discord / discord-example-app

Basic Discord app with examples
MIT License
514 stars 523 forks source link

Getting "Bad request signature" error while setting up interations endpoint URL #20

Open Arjun021 opened 1 year ago

Arjun021 commented 1 year ago

After running the example and running local server with ngrok . I set the URL in discord settings according to the doc but after that I am getting Bad request signature error.

image

It's coming from the utils.js file VerifyDiscordRequest function. How can we resolve this issue ?

jaku commented 1 year ago

You need to make sure the URL you're saving on Discord has /interactions at the end.

So don't just post https://asdfasdfasdfasd.ngrok.io, make sure it's https://asdfasdfasdfasd.ngrok.io/interactions

kvn-prhn commented 1 year ago

I'm getting a similar error message. I added /interactions on the end of my ngrok url I put in the discord endpoint url app setting.

Error: Bad request signature
    at <path>/discord-example-app/utils.js:13:13
    at <path>\discord-example-app\node_modules\body-parser\lib\read.js:111:9
    at AsyncResource.runInAsyncScope (node:async_hooks:204:9)
    at invokeCallback (<path>\discord-example-app\node_modules\raw-body\index.js:231:16)
    at done (<path>\discord-example-app\node_modules\raw-body\index.js:220:7)
    at IncomingMessage.onEnd (<path>\discord-example-app\node_modules\raw-body\index.js:280:7)
    at IncomingMessage.emit (node:events:513:28)
    at endReadableNT (node:internal/streams/readable:1359:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
kvn-prhn commented 1 year ago

Turns out my problem was that I copied the wrong token into DISCORD_TOKEN in .env. Once I copied the right thing it worked.

tflagg commented 1 year ago

I am currently experiencing this problem, where did you find the correct token? It provided me with one, which I assumed was the right one...but perhaps not.

lajawi commented 9 months ago

Turns out my problem was that I copied the wrong token into DISCORD_TOKEN in .env. Once I copied the right thing it worked.

I have a similar issue, but this doesn't fix it.

HaukHuang commented 8 months ago

Turns out my problem was that I copied the wrong token into DISCORD_TOKEN in .env. Once I copied the right thing it worked.

I have a similar issue, but this doesn't fix it.

Have you already solved this issue?

HaukHuang commented 8 months ago

image I'm also facing the same issue. I have outputted the relevant parameters and confirmed that the configurations are correct.

lajawi commented 8 months ago

Turns out my problem was that I copied the wrong token into DISCORD_TOKEN in .env. Once I copied the right thing it worked.

I have a similar issue, but this doesn't fix it.

Have you already solved this issue?

I started from scratch, so in a way, yes, but I didn't solve the issue itself.

uchijo commented 8 months ago

In my case, .env was not loaded correctly. I'm not sure it helps you, but here's my situation:

I was running app on docker compose, since I wanted to use it with cloudflare tunnel. Here's part of my docker-compose.yml, which did not work correctly:

version: '3.1'

services:
  app:
    image: node:latest
    command: node /app/app.js # this is not good. this way of invoking app.js won't load .env in the project root.
    volumes:
      - ./:/app/
  tunnel:
    image: cloudflare/cloudflared
    command: tunnel run
...

as written in comment, the way starting the server was not good. and this is the config which worked correctly:

version: '3.1'

services:
  app:
    image: node:latest
    working_dir: /app
    command: node app.js
    volumes:
      - ./:/app/
  tunnel:
    image: cloudflare/cloudflared
    command: tunnel run
...

Hope this helps someone :)

LK00100100 commented 6 months ago

I have problems registering* the INTERACTIONS ENDPOINT URL for on the Discord Bot Developer page.

There seemed to be a problem with the security-and-auth part (see discord developer doc link below).

These didn't work for me (and I used the debugger to check the values)

What worked was this using the verifyKeyMiddleware:

import { verifyKeyMiddleware } from 'discord-interactions';
app.post('/interactions', verifyKeyMiddleware(process.env.PUBLIC_KEY), async function (req, res) {