r/Discord_selfbots • u/FalseDog7020 • 6h ago
❔ Question Captcha solving error
I'm trying to create a guild joiner script with a captcha solver (nonecap) and I keep hitting a "Unknown message" error (code 10008), and I dont know what if could be.
import asyncio
import logging
import os
import time
import traceback
from typing import Optional
import discord
import requests
from dotenv import load_dotenv
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s %(levelname)s [%(name)s] %(message)s",
)
logger = logging.getLogger("captcha-bot")
load_dotenv()
NONECAP_KEY = os.getenv("NONECAP_KEY")
BOT_TOKEN = os.getenv("BOT_TOKEN")
INVITE_CODE = os.getenv("INVITE_CODE", "microsoft")
def solve_captcha(sitekey: str, rqdata: Optional[str] = None) -> str:
if not NONECAP_KEY:
raise RuntimeError("NONECAP_KEY missing from .env")
url = "https://api.nonecap.com/v1/solves"
headers = {"Authorization": f"Bearer {NONECAP_KEY}"}
pl = {
"type": "hcaptcha",
"sitekey": sitekey,
"url": f"https://discord.com/invites/{INVITE_CODE}",
}
if rqdata:
pl["rqdata"] = rqdata
logger.debug("Requesting captcha token: sitekey=%s invite=%s rqdata=%s", sitekey, INVITE_CODE, bool(rqdata))
try:
response = requests.post(
url,
params={"wait": 30},
headers=headers,
json=pl,
timeout=40,
)
logger.debug("NoneCAP response: status=%s content_type=%s", response.status_code, response.headers.get("Content-Type"))
response.raise_for_status()
result = response.json()
except requests.RequestException as exc:
logger.exception("NoneCAP request failed")
raise RuntimeError(f"NoneCAP request failed: {exc}") from exc
except ValueError as exc:
raise RuntimeError("NoneCAP returned invalid JSON") from exc
solve_id = result.get("id") if isinstance(result, dict) else None
deadline = time.monotonic() + 180
while time.monotonic() < deadline:
token = result.get("token") if isinstance(result, dict) else None
if token:
logger.debug("Captcha token received successfully for solve=%s", solve_id)
return token
if not solve_id:
error = result.get("error") if isinstance(result, dict) else None
raise RuntimeError(error or f"NoneCAP returned no solve ID or token: {result!r}")
status = result.get("status") if isinstance(result, dict) else None
error = result.get("error") if isinstance(result, dict) else None
if status in {"failed", "canceled", "cancelled", "expired"}:
raise RuntimeError(error or f"NoneCAP solve ended with status {status!r}")
logger.debug("Waiting for NoneCAP solve=%s status=%s", solve_id, status)
time.sleep(2)
try:
response = requests.get(
f"{url}/{solve_id}",
headers=headers,
timeout=40,
)
logger.debug("NoneCAP poll: status=%s http_status=%s", result.get("status") if isinstance(result, dict) else None, response.status_code)
response.raise_for_status()
result = response.json()
except requests.RequestException as exc:
logger.exception("NoneCAP polling failed")
raise RuntimeError(f"NoneCAP polling failed: {exc}") from exc
except ValueError as exc:
raise RuntimeError("NoneCAP polling returned invalid JSON") from exc
raise TimeoutError(f"Timed out waiting for NoneCAP solve {solve_id}")
class MyCaptchaHandler(discord.CaptchaHandler):
async def startup(self):
logger.debug("Captcha handler startup")
async def prefetch_token(self, proxy, _proxy_auth):
logger.debug("Captcha prefetch requested: proxy=%s proxy_auth=%s", bool(proxy), bool(_proxy_auth))
async def fetch_token(self, data, proxy, _proxy_auth):
sitekey = data.get("captcha_sitekey")
rqdata = data.get("captcha_rqdata")
logger.debug("Captcha response fields: %s", sorted(str(key) for key in data))
logger.debug("Captcha fetch requested: sitekey=%s rqdata=%s proxy=%s", sitekey, bool(rqdata), bool(proxy))
logger.debug("Captcha proxy context: proxy=%s proxy_auth=%s", bool(proxy), bool(_proxy_auth))
if not sitekey:
logger.error("Captcha data did not contain captcha_sitekey: %r", data)
raise RuntimeError("Discord captcha data did not contain captcha_sitekey")
return await asyncio.to_thread(solve_captcha, sitekey, rqdata)
client = discord.Client(captcha_handler=MyCaptchaHandler())
u/client.event
async def on_ready():
logger.info("Logged in as %s (%s)", client.user, getattr(client.user, "id", "unknown"))
try:
logger.info("Accepting invite %r", INVITE_CODE)
invite = await client.fetch_invite(INVITE_CODE)
if invite.guild:
guild_id = getattr(invite.guild, "id", None)
logger.info("Invite target: guild=%r guild_id=%s channel=%r", getattr(invite.guild, "name", None), guild_id, getattr(invite.channel, "name", None))
if guild_id is not None:
current_guild = client.get_guild(guild_id)
if current_guild is not None:
logger.warning("Account appears to already be in target guild %s", guild_id)
state = client._connection
context = discord.tracking.ContextProperties.from_accept_invite_page(
guild_id=getattr(invite.guild, "id", None),
channel_id=getattr(invite.channel, "id", None),
channel_type=getattr(invite.channel, "type", None),
)
data = await state.http.request(
discord.http.Route("POST", "/invites/{invite_id}", invite_id=invite.code),
context_properties=context,
json={},
)
accepted = discord.Invite.from_incomplete(state=state, data=data, message=invite._message)
logger.info("Successfully joined/accepted invite %r (invite code=%s)", INVITE_CODE, accepted.code)
except discord.HTTPException as exc:
logger.error("Discord rejected invite %r: status=%s code=%s message=%r", INVITE_CODE, exc.status, exc.code, exc.text)
logger.exception("Invite acceptance failed")
except Exception as exc:
logger.exception("Failed to accept invite %r: %s", INVITE_CODE, exc)
u/client.event
async def on_error(event, *args, **kwargs):
logger.error("Discord event error in %s", event)
logger.error("Event arguments: args=%r kwargs=%r", args, kwargs)
logger.error("Traceback:\n%s", traceback.format_exc())
if __name__ == "__main__":
if not BOT_TOKEN:
raise RuntimeError("BOT_TOKEN missing from .env")
if not NONECAP_KEY:
raise RuntimeError("NONECAP_KEY missing from .env")
logger.debug("Starting Discord client with invite %r", INVITE_CODE)
client.run(BOT_TOKEN)
and the logs
2026-11-24 10:22:59,494 WARNING [discord.client] PyNaCl is not installed, voice will NOT be supported.
2026-11-24 10:22:59,494 DEBUG [discord.client] on_ready has successfully been registered as an event
2026-11-24 10:22:59,494 DEBUG [discord.client] on_error has successfully been registered as an event
2026-11-24 10:22:59,494 DEBUG [captcha-bot] Starting Discord client with invite 'microsoft'
2026-11-24 10:22:59,494 DEBUG [asyncio] Using selector: KqueueSelector
2026-11-24 10:22:59 INFO discord.client Logging in using static token.
2026-11-24 10:22:59,494 INFO [discord.client] Logging in using static token.
2026-11-24 10:23:00 INFO discord.http Found user agent Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/159.0.0.0 Safari/537.36, build number 679544.
2026-11-24 10:23:00,413 INFO [discord.http] Found user agent Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/159.0.0.0 Safari/537.36, build number 679544.
2026-11-24 10:23:00,413 DEBUG [captcha-bot] Captcha handler startup
2026-11-24 10:23:06 INFO discord.gateway Connected to Gateway (Session ID: a362b6b8e542c2e69b0378b42685db23).
2026-11-24 10:23:06,148 INFO [discord.gateway] Connected to Gateway (Session ID: a362b6b8e542c2e69b0378b42685db23).
2026-11-24 10:23:06 WARNING discord.state Member list scraping failed for 1560310042249531404 (Failed to automatically choose channels; please specify them manually).
2026-11-24 10:23:06,340 WARNING [discord.state] Member list scraping failed for 1560310042249531404 (Failed to automatically choose channels; please specify them manually).
2026-11-24 10:23:06 WARNING discord.state Member list scraping failed for 1466978824964018270 (Failed to automatically choose channels; please specify them manually).
2026-11-24 10:23:06,340 WARNING [discord.state] Member list scraping failed for 1466978824964018270 (Failed to automatically choose channels; please specify them manually).
2026-11-24 10:23:06 WARNING discord.state Member list scraping failed for 1518863715259383909 (Failed to automatically choose channels; please specify them manually).
2026-11-24 10:23:06,340 WARNING [discord.state] Member list scraping failed for 1518863715259383909 (Failed to automatically choose channels; please specify them manually).
2026-11-24 10:23:06 WARNING discord.state Member list scraping failed for 1265348805893689396 (Failed to automatically choose channels; please specify them manually).
2026-11-24 10:23:06,340 WARNING [discord.state] Member list scraping failed for 1265348805893689396 (Failed to automatically choose channels; please specify them manually).
2026-11-24 10:23:06 WARNING discord.state Member list scraping failed for 1288957902870286468 (Failed to automatically choose channels; please specify them manually).
2026-11-24 10:23:06,340 WARNING [discord.state] Member list scraping failed for 1288957902870286468 (Failed to automatically choose channels; please specify them manually).
2026-11-24 10:23:06 WARNING discord.state Member list scraping failed for 1051676250059575387 (Failed to automatically choose channels; please specify them manually).
2026-11-24 10:23:06,340 WARNING [discord.state] Member list scraping failed for 1051676250059575387 (Failed to automatically choose channels; please specify them manually).
2026-11-24 10:23:06 WARNING discord.state Member list scraping failed for 1509671555511353467 (Failed to automatically choose channels; please specify them manually).
2026-11-24 10:23:06,340 WARNING [discord.state] Member list scraping failed for 1509671555511353467 (Failed to automatically choose channels; please specify them manually).
2026-11-24 10:23:07,983 INFO [captcha-bot] Logged in as p196hql#0 (935052002910687252)
2026-11-24 10:23:07,983 INFO [captcha-bot] Accepting invite 'microsoft'
2026-11-24 10:23:08,006 INFO [captcha-bot] Invite target: guild='Microsoft Community [Unofficial]' guild_id=150662382874525696 channel='server-information'
2026-11-24 10:23:08,789 DEBUG [captcha-bot] Captcha response fields: ['captcha_key', 'captcha_rqdata', 'captcha_rqtoken', 'captcha_service', 'captcha_session_id', 'captcha_sitekey']
2026-11-24 10:23:08,790 DEBUG [captcha-bot] Captcha fetch requested: sitekey=a9b5fb07-92ff-493f-86fe-352a2803b3df rqdata=True proxy=False
2026-11-24 10:23:08,790 DEBUG [captcha-bot] Captcha proxy context: proxy=False proxy_auth=False
2026-11-24 10:23:08,790 DEBUG [captcha-bot] Requesting captcha token: sitekey=a9b5fb07-92ff-493f-86fe-352a2803b3df invite=microsoft rqdata=True
2026-11-24 10:23:08,819 DEBUG [urllib3.connectionpool] Starting new HTTPS connection (1): api.nonecap.com:443
2026-11-24 10:23:18,651 DEBUG [urllib3.connectionpool] https://api.nonecap.com:443 "POST /v1/solves?wait=30 HTTP/1.1" 200 None
2026-11-24 10:23:18,654 DEBUG [captcha-bot] NoneCAP response: status=200 content_type=application/json
2026-11-24 10:23:18,654 DEBUG [captcha-bot] Captcha token received successfully for solve=solve_01M85YD3X0C32GEGW71NQ3F0Z9
2026-11-24 10:23:20,848 ERROR [captcha-bot] Discord rejected invite 'microsoft': status=403 code=10008 message='Unknown Message'
2026-11-24 10:23:20,848 ERROR [captcha-bot] Invite acceptance failed
Traceback (most recent call last):
File "/Users/hamdan/Documents/captcha-py/main.py", line 143, in on_ready
data = await state.http.request(
File "/Users/hamdan/Documents/captcha-py/.venv/lib/python3.9/site-packages/discord/http.py", line 830, in request
raise Forbidden(response, data)
discord.errors.Forbidden: 403 Forbidden (error code: 10008): Unknown Message
2026-11-24 10:23:22 INFO discord.gateway Gateway session has been invalidated.
2026-11-24 10:23:22,288 INFO [discord.gateway] Gateway session has been invalidated.
Traceback (most recent call last):
File "/Users/hamdan/Documents/captcha-py/main.py", line 171, in <module>
client.run(BOT_TOKEN)
File "/Users/hamdan/Documents/captcha-py/.venv/lib/python3.9/site-packages/discord/client.py", line 938, in run
asyncio.run(runner())
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
return future.result()
File "/Users/hamdan/Documents/captcha-py/.venv/lib/python3.9/site-packages/discord/client.py", line 927, in runner
await self.start(token, reconnect=reconnect)
File "/Users/hamdan/Documents/captcha-py/.venv/lib/python3.9/site-packages/discord/client.py", line 858, in start
await self.connect(reconnect=reconnect)
File "/Users/hamdan/Documents/captcha-py/.venv/lib/python3.9/site-packages/discord/client.py", line 738, in connect
await self.ws.poll_event()
File "/Users/hamdan/Documents/captcha-py/.venv/lib/python3.9/site-packages/discord/gateway.py", line 671, in poll_event
raise ConnectionClosed(self.socket, code=code) from None
discord.errors.ConnectionClosed: WebSocket closed with 4004can someone help
1
Upvotes
1
u/mfdi_ 3h ago
Either you made this as a beginner or AI made it. Either way you need to stop using requests as it is outdated and for your aims will not do. If you already using python, use discord.py-self.