wop's picture
Update app.py
fe09635 verified
raw
history blame contribute delete
No virus
1.55 kB
# IMPORTANT: MAKE IT PRIVATE FROM SETTINGS + FEEL FRE TO REMOVE THIS, PLEASE KEEP THIS CODE ARCHITECTURE FOR GRADIO TO BE DISPLAYED, IF GRADIO NOT DISPLAYED, SPACE STOPS AFTER 30 MINUTES. YOU MUST VISIT THIS SPACE ONCE 48 HOURS TO RESET 48 HOUR COUNTDOWN (when countdown reaches 0, the space stops running)
import asyncio
import os
import threading
import random
from threading import Event
from typing import Optional
import requests
import discord
import gradio as gr
from gradio_client import Client
from discord import Permissions
from discord.ext import commands
from discord.utils import oauth_url
from gradio_client.utils import QueueError
event = Event()
async def wait(job):
while not job.done():
await asyncio.sleep(0.2)
# settings v ####################################################################
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
intents = discord.Intents.all()
bot = commands.Bot(command_prefix="$", intents=intents, help_command=None)
# bot stuff v ####################################################################
# end of stuff v ####################################################################
# running in thread
def run_bot():
if not DISCORD_TOKEN:
print("DISCORD_TOKEN NOT SET")
event.set()
else:
bot.run(DISCORD_TOKEN)
threading.Thread(target=run_bot).start()
event.wait()
with gr.Blocks() as demo:
gr.Markdown(
f"""
# Discord bot is online!
"""
)
demo.launch()