Skip to content

Commit

Permalink
Fix image generation error
Browse files Browse the repository at this point in the history
  • Loading branch information
Zingzy committed Dec 21, 2023
1 parent 18a8850 commit 4af8219
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 23 deletions.
12 changes: 6 additions & 6 deletions cogs/imagine_cog.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import datetime
import random
import discord
from discord import app_commands, ui
from discord.ext import commands
from discord.ui import Button
import json

from utils import *
from constants import *
Expand Down Expand Up @@ -232,8 +229,11 @@ async def multiimagine_command(self, interaction, prompt:str, width:int = 1000,
file_name = f"{prompt}_{idx}.png"
files.append(discord.File(img, file_name))

response = await interaction.followup.send(f'## `{prompt}` - {interaction.user.mention}\n{description}', files=files, ephemeral= False) if private else await interaction.channel.send(f'## `{prompt}` - {interaction.user.mention}\n{description}', files=files)

if not len(files) == 0:
response = await interaction.followup.send(f'## `{prompt}` - {interaction.user.mention}\n{description}', files=files, ephemeral= False) if private else await interaction.channel.send(f'## `{prompt}` - {interaction.user.mention}\n{description}', files=files)
else:
await interaction.followup.send(embed=discord.Embed(title="Error", description="No images were generated", color=discord.Color.red()), ephemeral=True)
return
# id = response.id
# dic["message_id"] = id
# dic["type"] = "multi"
Expand Down Expand Up @@ -285,7 +285,7 @@ async def multiimagine_command_error(

embed = discord.Embed(
title="⏳ Cooldown",
description=f"You have to wait until **{end_time_ts}** ({time_left}) before using the <multi-imagine:1187375074722975837> again.",
description=f"You have to wait until **{end_time_ts}** ({time_left}) before using the </multi-imagine:1187375074722975837> again.",
color=discord.Color.red(),
)

Expand Down
1 change: 0 additions & 1 deletion constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
from dotenv import load_dotenv
import json

load_dotenv()

Expand Down
24 changes: 11 additions & 13 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
from pymongo import MongoClient
from dotenv import load_dotenv
import os
import json
import requests
import datetime
import discord
from discord.ext import commands
from discord import app_commands, ui
from api import *
import statistics
import time
Expand Down Expand Up @@ -42,7 +39,7 @@
- **enhance** 🖼️ : Specifies whether to enhance the image prompt or not (default True)
- **private** 🔒 : when set to True the generated Image will only be visible to you
""",
"</help:1125407202388230155> ❓": "Displays this",
"</help:1187383172992872509> ❓": "Displays this",
}


Expand Down Expand Up @@ -85,18 +82,19 @@ async def load():

@bot.event
async def on_message(message):
if message.author == bot.user:
return
if message.author == bot.user:
return

if bot.user in message.mentions:
embed = discord.Embed(
description="Hello, I am the Pollinations.ai Bot. I am here to help you with your AI needs. Type `!help` or click </help:1125407202388230155> to get started.",
color=discord.Color.og_blurple(),
)
if bot.user in message.mentions:
if message.type is not discord.MessageType.reply:
embed = discord.Embed(
description="Hello, I am the Pollinations.ai Bot. I am here to help you with your AI needs. Type `!help` or click </help:1187383172992872509> to get started.",
color=discord.Color.og_blurple(),
)

await message.reply(embed=embed)
await message.reply(embed=embed)

await bot.process_commands(message)
await bot.process_commands(message)


@bot.command()
Expand Down
5 changes: 2 additions & 3 deletions utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import discord.ext
import requests
import random
from constants import *
import aiohttp
import io
from urllib.parse import quote
from pymongo import MongoClient
import sys

client = MongoClient(MONGODB_URI)

Expand Down Expand Up @@ -61,7 +60,7 @@ async def generate_image(
model = model.lower()

print(
f"Generating image with prompt: {prompt}, width: {width}, height: {height}, model: {model}, negative: {negative}, cached: {cached}, nologo: {nologo}, enhance: {enhance}"
f"Generating image with prompt: {prompt}, width: {width}, height: {height}, model: {model}, negative: {negative}, cached: {cached}, nologo: {nologo}, enhance: {enhance}", file=sys.stderr
)

seed = str(random.randint(0, 1000000000))
Expand Down

0 comments on commit 4af8219

Please sign in to comment.