Tonic-bot / app.py
not-lain's picture
Synced repo using 'sync_with_huggingface' Github Action
d971fec
raw
history blame
814 Bytes
import gradio as gr
import dotenv
import discord
import os
import threading
from threading import Event
event = Event()
dotenv.load_dotenv()
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
intents = discord.Intents.default()
intents.message_content = True
bot = discord.Bot(intents=intents)
@bot.event
async def on_ready():
print(f"logged as {bot.user}")
event.set()
@bot.slash_command(name='ping',description='ping')
async def ping(ctx):
await ctx.respond(f"{bot.latency*1000:.0f}ms")
# 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 iface :
gr.Markdown("# welcome to Tonic-bot")
iface.queue().launch()