Python — Flask + discord.py
A multi-threaded implementation integrating Flask and discord.py to run parallel on the same host.
# pip install discord.py requests flask
import discord
import requests
import asyncio
from flask import Flask, request, jsonify
from threading import Thread
# ================= CONFIG =================
DISCORD_TOKEN = "YOUR_BOT_TOKEN"
Botliy_API_TOKEN = "YOUR_Botliy_API_TOKEN"
BOT_ID = "YOUR_BOT_ID"
WEBHOOK_SECRET = "your_webhook_secret_here"
VOTE_CHANNEL_ID = 123456789012345678
# ==========================================
intents = discord.Intents.default()
client = discord.Client(intents=intents)
app = Flask(__name__)
@app.route('/Botliy/webhook', methods=['POST'])
def Botliy_webhook():
if request.headers.get('Authorization') != WEBHOOK_SECRET:
return jsonify({"error": "Unauthorized"}), 401
user_id = request.json.get("user")
asyncio.run_coroutine_threadsafe(
send_vote_message(user_id),
client.loop
)
return jsonify({"status": "success"}), 200
async def send_vote_message(user_id):
channel = client.get_channel(VOTE_CHANNEL_ID)
if channel:
embed = discord.Embed(
title="🎉 New Vote Received!",
description=f"<@{user_id}> just voted!",
color=discord.Color.blurple()
)
await channel.send(embed=embed)
async def post_stats():
await client.wait_until_ready()
while not client.is_closed():
requests.post(
f"https://Botliy.online/api/bots/{BOT_ID}/stats",
json={"server_count": len(client.guilds), "shard_count": 1},
headers={"Authorization": Botliy_API_TOKEN}
)
await asyncio.sleep(1800)
@client.event
async def on_ready():
client.loop.create_task(post_stats())
def run_webhook():
app.run(host="0.0.0.0", port=8999)
if __name__ == "__main__":
Thread(target=run_webhook).start()
client.run(DISCORD_TOKEN)