FireHead90544 / craiyon.py

Unofficial API Wrapper for craiyon.com (DAL-E-MINI). Generate awesome images from text tokens.
Apache License 2.0
69 stars 22 forks source link

Error while used for discord bot #21

Open mdxabu opened 6 months ago

mdxabu commented 6 months ago

Code:

@app_commands.command(name="texttoimg",description="Give your prompt to generate image")
    async def texttoimg(self,interaction: discord.Interaction,prompt: str):
        # await interaction.response.send_message("Generating: "+prompt+" ....")
        generator = Craiyon()
        generated_images = await generator.async_generate(prompt)
        b64_list = await craiyon_utils.async_encode_base64(generated_images.images) 

        images1 = []
        for index, image in enumerate(b64_list):
            img_bytes = BytesIO(base64.b64decode(image)) 
            # image = discord.File(img_bytes)
            image =  discord.File(img_bytes)
            image.filename = f"result{index}.webp"
            images1.append(image)         
        await interaction.response.send_message(files=images1)

Output:

image

If i print in console it works well, but doesn't send img to discord