Just a simple Python script to proxy discord webhook requests.
import requests
import uvicorn
import fastapi
app = fastapi.FastAPI(title="WebhookProxy")
@app.get("/")
async def read_root():
"""Redirect To Docs."""
return fastapi.responses.RedirectResponse("./docs")
@app.post("/webhooks/{webhook_id}/{webhook_token}")
async def proxy_webhook(webhook_id: str, webhook_token: str, request: fastapi.Request):
"""Discord Webhook Proxy."""
discord_webhook_url = f"https://discord.com/api/webhooks/{webhook_id}/{webhook_token}"
JSONResponse = fastapi.responses.JSONResponse
try:
data = await request.json()
response = requests.post(discord_webhook_url, json=data)
if response.status_code == 204:
return JSONResponse(content={"status": "success"}, status_code=200)
else:
return JSONResponse(content={"error": "Failed to forward message", "details": response.text}, status_code=response.status_code)
except Exception as e:
return JSONResponse(content={"error": str(e)}, status_code=500)
uvicorn.run(app, host="0.0.0.0", port=80)
#pip install requests uvicorn fastapi