File size: 814 Bytes
463123f d971fec 463123f d971fec 463123f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
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()
|