Home > Back-end >  Captcha Image in Embed
Captcha Image in Embed

Time:10-11

i am trying to make a Captcha-Verification System, I managed to get my bot to send the captcha image and now I wanted to ask if/how I can send the captcha image in an embed?

Here would be the "Save" code:

 # Save
        image.save(f"{folderPath}/output/{captchaName}_2.png")
        data = getConfig(member.guild.id)
        captchaChannel = self.client.get_channel(data["captchaChannel"])
        captchaLog = self.client.get_channel(data["captchaLog"])
        try:
            captchaFile = discord.File(f"{folderPath}/output/{captchaName}_2.png")
            captcha_embed = discord.Embed(title=f"{ctx.guild.name} Captcha Verification",
                                          description="Please return the code written on the Captcha.")
            captchaEmbed = await member.send(embed=captcha_embed, file=captchaFile)
        except discord.errors.Forbidden:
            pass

How can I attach the captcha image to this embed? Is there a way?

CodePudding user response:

In order to add an image to a discord Embed, you can use the discord.Embed.set_image method. It takes the image url as an argument.

But in this case, since you need to add a local image, you can first create a discord.File using the local image, then pass attachment://filename as url.

Example

file = discord.File("path/to/my/image.png", filename="image.png")
embed = discord.Embed()
embed.set_image(url="attachment://image.png")
await channel.send(file=file, embed=embed)

This is an example provided in the discord.py documentation under FAQ found here

  • Related