Nabeel Munir
Nabeel Munir

Reputation: 63

Making POST request to discord server in nodejs

I am trying to make a post request to the following endpoint:

`https://discord.com/api/v9/invites/${link}`

But, i keep getting the following response:

{
  captcha_key: [ 'captcha-required' ],
  captcha_sitekey: '4c672d35-0701-42b2-88c3-78380b0db560',
  captcha_service: 'hcaptcha'
}

What i am trying to do is to write a script where i can join a discord server from a provided discord server invite link.

Below is the function I am using to make a request.

const fetch_request = async (link, options) => {
  if (typeof link !== "string") throw new Error("Couldn't fetch");
  return new Promise((res, rej) => {
      fetch(`https://discord.com/api/v9/invites/${link}`, {
          headers: {
              "accept": "*/*",
              "accept-language": "en-US",
              "authorization": "<user_token_here>",
              "content-type": "application/json",
              "sec-fetch-dest": "empty",
              "sec-fetch-mode": "cors",
              "sec-fetch-site": "same-origin",
              "x-discord-locale": "en-US",
              "origin": "https://discord.com",
              referer: `https://discord.com/channels/@me`,
              mode: "cors",
          },
          body: JSON.stringify('{}'),
          method: 'POST'
              
        }).then((response) => {
          if (options.parse) {
              response.json().then((m) => {
                  res(m);
              });
          } else {
              res(response);
          }
      });
  });
}

The request seems to be made but, how do I bypass this capctha. I checked headers, they seem to be ok to me. How do I get the user to join a guild using discord api?

Thank you for help.

Upvotes: 0

Views: 1965

Answers (2)

vlonezero
vlonezero

Reputation: 39

I was just trying the same thing as you, check out 2Captcha's API .

It's very cheap, all you need is to get "captcha_key" and add it to your request next time.

Upvotes: 0

Flavio Lugli
Flavio Lugli

Reputation: 36

You need to solve the captchas, i suggest you solving them with a service like 2captchas or other similar options, they are super cheap and usually don't take too long to setup.

Upvotes: 1

Related Questions