Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: Failed to send message: 400 {'captcha_key': ['captcha-required'] #62

Open
CodecNomad opened this issue Aug 16, 2023 · 0 comments

Comments

@CodecNomad
Copy link

CodecNomad commented Aug 16, 2023

Hey man! Could you guide me with this? What am I doing wrong?

async def send_message(self, message, api_key: str):
    headers = self.__get_headers()

    async with self.__session.post(
            f"{self.BASE_URL}{self.TYPE_ENDPOINT_START}{self.channel_id}{self.TYPE_ENDPOINT_END}", headers=headers,
    ) as response:
        if response.status == 204:
            pass
        else:
            raise ValueError(f"Failed to type: {response.status} {await response.json()}")

    async with self.__session.post(
            f"{self.BASE_URL}{self.SEND_ENDPOINT_START}{self.channel_id}{self.SEND_ENDPOINT_END}", headers=headers,
            json={"content": message, "flags": 0, "nonce": "f4yh5", "tts": False}
    ) as response:
        if response.status == 200:
            data = await response.json()
            self.__message_id = data["id"]
            return data["id"]
        else:
            data = await response.json()
            solver = TwoCaptcha(apiKey=api_key)
            result = await solver.hcaptcha(
                sitekey="a9b5fb07-92ff-493f-86fe-352a2803b3df",
                url='https://discord.com/',
                data=data['captcha_rqdata'],
                invisible=True,
                UserAgent='Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) '
                      'discord/1.0.9016 Chrome/108.0.5359.215 Electron/22.3.12 Safari/537.36'
                )
            headers.update({"X-Captcha-Key": result["code"]})
            async with self.__session.post(
                    f"{self.BASE_URL}{self.SEND_ENDPOINT_START}{self.channel_id}{self.SEND_ENDPOINT_END}",
                    headers=headers,
                    json={"content": message, "flags": 0, "nonce": "nonce", "tts": False}
            ) as resp:
                if resp.status == 200:
                    data = await resp.json()
                    self.__message_id = data["id"]
                    return data["id"]
                else:
                    raise ValueError(f"Failed to send message: {resp.status} {await resp.json()}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant