Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,7 +19,7 @@ event = Event()
|
|
| 19 |
|
| 20 |
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
|
| 21 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 22 |
-
API_URL = "https://api-inference.huggingface.co/models/
|
| 23 |
headers = {"Authorization": "Bearer " + HF_TOKEN}
|
| 24 |
|
| 25 |
def ask(input_text):
|
|
@@ -59,7 +59,7 @@ async def uptime(ctx):
|
|
| 59 |
embed.add_field(name="Uptime", value=f"{days} days, {hours} hours, {minutes} minutes, {seconds} seconds", inline=False)
|
| 60 |
embed.set_footer(text="Created by Cosmos")
|
| 61 |
|
| 62 |
-
await ctx.
|
| 63 |
|
| 64 |
@bot.command()
|
| 65 |
async def ai(ctx, *, input_text: str):
|
|
@@ -68,24 +68,22 @@ async def ai(ctx, *, input_text: str):
|
|
| 68 |
result = ask(input_text)
|
| 69 |
|
| 70 |
# Reply with the embed
|
| 71 |
-
await ctx.
|
| 72 |
|
| 73 |
-
def query(
|
| 74 |
-
|
| 75 |
-
response = requests.post(API_URL, headers=headers, json=payload)
|
| 76 |
return response.content
|
| 77 |
|
| 78 |
@bot.command()
|
| 79 |
async def img(ctx, *, prompt: str):
|
| 80 |
# Query the API to generate the image
|
| 81 |
async with ctx.typing():
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
# Send the image as a file
|
| 88 |
-
await ctx.
|
| 89 |
|
| 90 |
|
| 91 |
@bot.command()
|
|
@@ -103,7 +101,7 @@ async def verse(ctx):
|
|
| 103 |
# Create an embed
|
| 104 |
embed = discord.Embed(title="Random Bible Verse", description=passage, color=discord.Color.blue())
|
| 105 |
embed.set_footer(text="Created by Cosmos")
|
| 106 |
-
await ctx.
|
| 107 |
|
| 108 |
@bot.command()
|
| 109 |
@commands.has_permissions(kick_members=True)
|
|
@@ -111,11 +109,11 @@ async def kick(ctx, member: discord.Member, *, reason: Optional[str] = "No reaso
|
|
| 111 |
"""Kicks a member."""
|
| 112 |
try:
|
| 113 |
await member.kick(reason=reason)
|
| 114 |
-
await ctx.
|
| 115 |
except discord.Forbidden:
|
| 116 |
-
await ctx.
|
| 117 |
except discord.HTTPException:
|
| 118 |
-
await ctx.
|
| 119 |
|
| 120 |
@bot.command()
|
| 121 |
@commands.has_permissions(ban_members=True)
|
|
@@ -123,11 +121,11 @@ async def ban(ctx, member: discord.Member, *, reason: Optional[str] = "No reason
|
|
| 123 |
"""Bans a member."""
|
| 124 |
try:
|
| 125 |
await member.ban(reason=reason)
|
| 126 |
-
await ctx.
|
| 127 |
except discord.Forbidden:
|
| 128 |
-
await ctx.
|
| 129 |
except discord.HTTPException:
|
| 130 |
-
await ctx.
|
| 131 |
|
| 132 |
|
| 133 |
@bot.command()
|
|
@@ -145,7 +143,7 @@ async def cmds(ctx):
|
|
| 145 |
embed.add_field(name="Bot Information", value=bot_info, inline=False)
|
| 146 |
embed.set_footer(text="Created by Cosmos")
|
| 147 |
|
| 148 |
-
await ctx.
|
| 149 |
|
| 150 |
async def update_status():
|
| 151 |
await bot.wait_until_ready() # Wait until the bot is fully ready
|
|
@@ -231,7 +229,7 @@ async def search(ctx, *, query: str):
|
|
| 231 |
embed = discord.Embed(title="Search Results", description="Unable to fetch search results.", color=discord.Color.red())
|
| 232 |
|
| 233 |
embed.set_footer(text="Created by Cosmos")
|
| 234 |
-
await ctx.
|
| 235 |
|
| 236 |
@bot.command()
|
| 237 |
@commands.has_permissions(manage_messages=True)
|
|
@@ -239,21 +237,21 @@ async def purge(ctx, limit: int):
|
|
| 239 |
"""Removes N amount of messages."""
|
| 240 |
try:
|
| 241 |
await ctx.channel.purge(limit=limit + 1) # Add 1 to include the command message itself
|
| 242 |
-
await ctx.
|
| 243 |
except discord.Forbidden:
|
| 244 |
-
await ctx.
|
| 245 |
except discord.HTTPException:
|
| 246 |
-
await ctx.
|
| 247 |
|
| 248 |
|
| 249 |
@bot.event
|
| 250 |
async def on_command_error(ctx, error):
|
| 251 |
if isinstance(error, commands.CommandNotFound):
|
| 252 |
-
await ctx.
|
| 253 |
elif isinstance(error, commands.MissingRequiredArgument):
|
| 254 |
-
await ctx.
|
| 255 |
elif isinstance(error, commands.CheckFailure):
|
| 256 |
-
await ctx.
|
| 257 |
else:
|
| 258 |
# Log the error to console or your logging system
|
| 259 |
print(f"An error occurred: {error}")
|
|
|
|
| 19 |
|
| 20 |
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
|
| 21 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 22 |
+
API_URL = "https://api-inference.huggingface.co/models/prompthero/openjourney"
|
| 23 |
headers = {"Authorization": "Bearer " + HF_TOKEN}
|
| 24 |
|
| 25 |
def ask(input_text):
|
|
|
|
| 59 |
embed.add_field(name="Uptime", value=f"{days} days, {hours} hours, {minutes} minutes, {seconds} seconds", inline=False)
|
| 60 |
embed.set_footer(text="Created by Cosmos")
|
| 61 |
|
| 62 |
+
await ctx.reply(embed=embed)
|
| 63 |
|
| 64 |
@bot.command()
|
| 65 |
async def ai(ctx, *, input_text: str):
|
|
|
|
| 68 |
result = ask(input_text)
|
| 69 |
|
| 70 |
# Reply with the embed
|
| 71 |
+
await ctx.reply(result)
|
| 72 |
|
| 73 |
+
def query(payload):
|
| 74 |
+
response = requests.post(API_URL_imgen, headers=headers_imgen, json=payload)
|
|
|
|
| 75 |
return response.content
|
| 76 |
|
| 77 |
@bot.command()
|
| 78 |
async def img(ctx, *, prompt: str):
|
| 79 |
# Query the API to generate the image
|
| 80 |
async with ctx.typing():
|
| 81 |
+
image_bytes = query({
|
| 82 |
+
"inputs": prompt,
|
| 83 |
+
})
|
| 84 |
+
image_file = discord.File(io.BytesIO(image_bytes), filename='generated_image.png')
|
|
|
|
| 85 |
# Send the image as a file
|
| 86 |
+
await ctx.reply(file=image_file)
|
| 87 |
|
| 88 |
|
| 89 |
@bot.command()
|
|
|
|
| 101 |
# Create an embed
|
| 102 |
embed = discord.Embed(title="Random Bible Verse", description=passage, color=discord.Color.blue())
|
| 103 |
embed.set_footer(text="Created by Cosmos")
|
| 104 |
+
await ctx.reply(embed=embed)
|
| 105 |
|
| 106 |
@bot.command()
|
| 107 |
@commands.has_permissions(kick_members=True)
|
|
|
|
| 109 |
"""Kicks a member."""
|
| 110 |
try:
|
| 111 |
await member.kick(reason=reason)
|
| 112 |
+
await ctx.reply(f"{member.mention} has been kicked. Reason: {reason}")
|
| 113 |
except discord.Forbidden:
|
| 114 |
+
await ctx.reply("I don't have permission to kick members.")
|
| 115 |
except discord.HTTPException:
|
| 116 |
+
await ctx.reply("An error occurred while trying to kick the member. Please try again later.")
|
| 117 |
|
| 118 |
@bot.command()
|
| 119 |
@commands.has_permissions(ban_members=True)
|
|
|
|
| 121 |
"""Bans a member."""
|
| 122 |
try:
|
| 123 |
await member.ban(reason=reason)
|
| 124 |
+
await ctx.reply(f"{member.mention} has been banned. Reason: {reason}")
|
| 125 |
except discord.Forbidden:
|
| 126 |
+
await ctx.reply("I don't have permission to ban members.")
|
| 127 |
except discord.HTTPException:
|
| 128 |
+
await ctx.reply("An error occurred while trying to ban the member. Please try again later.")
|
| 129 |
|
| 130 |
|
| 131 |
@bot.command()
|
|
|
|
| 143 |
embed.add_field(name="Bot Information", value=bot_info, inline=False)
|
| 144 |
embed.set_footer(text="Created by Cosmos")
|
| 145 |
|
| 146 |
+
await ctx.reply(embed=embed)
|
| 147 |
|
| 148 |
async def update_status():
|
| 149 |
await bot.wait_until_ready() # Wait until the bot is fully ready
|
|
|
|
| 229 |
embed = discord.Embed(title="Search Results", description="Unable to fetch search results.", color=discord.Color.red())
|
| 230 |
|
| 231 |
embed.set_footer(text="Created by Cosmos")
|
| 232 |
+
await ctx.reply(embed=embed)
|
| 233 |
|
| 234 |
@bot.command()
|
| 235 |
@commands.has_permissions(manage_messages=True)
|
|
|
|
| 237 |
"""Removes N amount of messages."""
|
| 238 |
try:
|
| 239 |
await ctx.channel.purge(limit=limit + 1) # Add 1 to include the command message itself
|
| 240 |
+
await ctx.reply(f"{limit} messages have been purged.")
|
| 241 |
except discord.Forbidden:
|
| 242 |
+
await ctx.reply("I don't have permission to manage messages.")
|
| 243 |
except discord.HTTPException:
|
| 244 |
+
await ctx.reply("An error occurred while trying to purge messages. Please try again later.")
|
| 245 |
|
| 246 |
|
| 247 |
@bot.event
|
| 248 |
async def on_command_error(ctx, error):
|
| 249 |
if isinstance(error, commands.CommandNotFound):
|
| 250 |
+
await ctx.reply("Sorry, I couldn't find that command. Use `$cmds` to see the list of available commands.")
|
| 251 |
elif isinstance(error, commands.MissingRequiredArgument):
|
| 252 |
+
await ctx.reply("Oops! Looks like you're missing some required arguments.")
|
| 253 |
elif isinstance(error, commands.CheckFailure):
|
| 254 |
+
await ctx.reply("You do not have the permissions to execute this command.")
|
| 255 |
else:
|
| 256 |
# Log the error to console or your logging system
|
| 257 |
print(f"An error occurred: {error}")
|