wop commited on
Commit
f4645b0
·
verified ·
1 Parent(s): efd95e1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -20
app.py CHANGED
@@ -1,24 +1,27 @@
1
- import asyncio
2
  import os
3
- import threading
4
- from threading import Event
5
- from typing import Optional
6
-
7
  import datetime
8
  import requests
9
- import discord
10
  import gradio as gr
11
  import gradio_client as grc
12
- from discord import Permissions
13
- from discord.ext import commands
14
- from discord.utils import oauth_url
15
- from gradio_client.utils import QueueError
16
 
17
  event = Event()
18
 
19
  DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
20
  HF_TOKEN = os.getenv("HF_TOKEN")
21
 
 
 
 
 
 
22
  async def wait(job):
23
  while not job.done():
24
  await asyncio.sleep(0.2)
@@ -36,11 +39,11 @@ def truncate_response(response: str) -> str:
36
  else:
37
  return response
38
 
39
- intents = discord.Intents.all()
40
- bot = commands.Bot(command_prefix="$", intents=intents, help_command=None)
41
-
42
- @bot.command()
43
- async def uptime(ctx):
44
  """Displays the uptime of the bot."""
45
  delta = datetime.datetime.utcnow() - bot.start_time
46
  hours, remainder = divmod(int(delta.total_seconds()), 3600)
@@ -54,8 +57,11 @@ async def uptime(ctx):
54
 
55
  await ctx.send(embed=embed)
56
 
57
- @bot.command()
58
- async def verse(ctx):
 
 
 
59
  """Returns a random Bible verse."""
60
  # Fetch a random Bible verse
61
  bible_api_url = "https://labs.bible.org/api/?passage=random&type=json"
@@ -71,8 +77,11 @@ async def verse(ctx):
71
  embed.set_footer(text="Created by Cosmos")
72
  await ctx.send(embed=embed)
73
 
74
- @bot.command()
75
- async def cmds(ctx):
 
 
 
76
  """Returns a list of commands and bot information."""
77
  # Get list of commands
78
  command_list = [f"{command.name}: {command.help}" for command in bot.commands]
@@ -126,7 +135,6 @@ async def on_member_join(member):
126
 
127
  await channel.send(embed=embed)
128
 
129
-
130
  # running in thread
131
  def run_bot():
132
  if not DISCORD_TOKEN:
 
 
1
  import os
2
+ import discord
3
+ from discord.ext import commands
4
+ from discord_slash import SlashCommand, SlashContext
5
+ from discord_slash.utils.manage_commands import create_option
6
  import datetime
7
  import requests
 
8
  import gradio as gr
9
  import gradio_client as grc
10
+ import asyncio
11
+ import threading
12
+ from threading import Event
13
+ from typing import Optional
14
 
15
  event = Event()
16
 
17
  DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
18
  HF_TOKEN = os.getenv("HF_TOKEN")
19
 
20
+ # Initialize bot and slash commands
21
+ intents = discord.Intents.all()
22
+ bot = commands.Bot(command_prefix="$", intents=intents)
23
+ slash = SlashCommand(bot, sync_commands=True) # Sync commands on start-up
24
+
25
  async def wait(job):
26
  while not job.done():
27
  await asyncio.sleep(0.2)
 
39
  else:
40
  return response
41
 
42
+ @slash.slash(
43
+ name="uptime",
44
+ description="Displays the uptime of the bot.",
45
+ )
46
+ async def uptime(ctx: SlashContext):
47
  """Displays the uptime of the bot."""
48
  delta = datetime.datetime.utcnow() - bot.start_time
49
  hours, remainder = divmod(int(delta.total_seconds()), 3600)
 
57
 
58
  await ctx.send(embed=embed)
59
 
60
+ @slash.slash(
61
+ name="verse",
62
+ description="Returns a random Bible verse."
63
+ )
64
+ async def verse(ctx: SlashContext):
65
  """Returns a random Bible verse."""
66
  # Fetch a random Bible verse
67
  bible_api_url = "https://labs.bible.org/api/?passage=random&type=json"
 
77
  embed.set_footer(text="Created by Cosmos")
78
  await ctx.send(embed=embed)
79
 
80
+ @slash.slash(
81
+ name="cmds",
82
+ description="Returns a list of commands and bot information."
83
+ )
84
+ async def cmds(ctx: SlashContext):
85
  """Returns a list of commands and bot information."""
86
  # Get list of commands
87
  command_list = [f"{command.name}: {command.help}" for command in bot.commands]
 
135
 
136
  await channel.send(embed=embed)
137
 
 
138
  # running in thread
139
  def run_bot():
140
  if not DISCORD_TOKEN: