Skip to content

Commit 6e2fc6d

Browse files
authored
Merge pull request #147 from PyBotDevs/add-embedbuilder-command
Add `/embedbuilder` command
2 parents 2fa8119 + 7afbb6f commit 6e2fc6d

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

framework/isobot/embedengine.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""The library used for designing and outputting Discord embeds."""
2+
import discord
3+
from discord import Color
4+
5+
6+
def embed(title: str, desc: str, *, image: str = None, thumbnail: str = None, color:int=None, footer_text: str = None, footer_img: str = None):
7+
"""Designs a Discord embed.
8+
-----------------------------------------------------------
9+
The color argument is completely optional.
10+
- If a color is set, it will return the embed in that color only.
11+
- If the color is set as "rand", then it will return the embed with a random color.
12+
- If a color is not set, it will appear as Discord's blurple embed color.
13+
"""
14+
if color == -1: color = Color.random()
15+
elif color == None: color = Color.blurple()
16+
local_embed = discord.Embed(
17+
title=title,
18+
description=desc,
19+
colour=color
20+
)
21+
if image is not None: local_embed.set_image(url=image)
22+
if thumbnail is not None: local_embed.set_thumbnail(url=thumbnail)
23+
if footer_text is not None and footer_img is not None: local_embed.set_footer(text=footer_text, icon_url=footer_img)
24+
elif footer_text is not None: local_embed.set_footer(text=footer_text)
25+
elif footer_img is not None: local_embed.set_footer(icon_url=footer_img)
26+
return local_embed

main.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import framework.isobot.colors
66
import framework.isobank.authorize
77
import framework.isobank.manager
8+
import framework.isobot.embedengine
89
import discord
910
from discord.ext import commands, tasks
1011
from discord.ext.commands import *
@@ -993,6 +994,23 @@ async def repo(ctx:SlashContext):
993994
localembed = discord.Embed(title="Source-code Repositories", description="See and contribute to **isobot lazer's [GitHub repository](https://github.com/PyBotDevs/isobot-lazer)**\nSee our **[GitHub organization](https://github.com/PyBotDevs)**", color=discord.Color.random())
994995
await ctx.send(embed=localembed)
995996

997+
@slash.slash(
998+
name="embedbuilder",
999+
description="Builds a custom embed however you want",
1000+
options=[
1001+
create_option(name="title", description="The title of the embed", option_type=3, required=True),
1002+
create_option(name="description", description="The body of the embed", option_type=3, required=True),
1003+
create_option(name="image_url", description="The main image you want to show for the embed (URL ONLY)", option_type=3, required=False),
1004+
create_option(name="thumbnail_url", description="The thumbnail image you want to show for the embed (URL ONLY)", option_type=3, required=False),
1005+
create_option(name="color", description="The embed's accent color (Use -1 for random color)", option_type=4, required=False),
1006+
create_option(name="footer_text", description="The text at the footer of the embed", option_type=3, required=False),
1007+
create_option(name="footer_icon_url", description="The icon you want to show in the embed (URL ONLY)", option_type=3, required=False)
1008+
]
1009+
)
1010+
async def embedbuilder(ctx:SlashContext, title: str, description: str, image_url: str = None, thumbnail_url: str = None, color: int = None, footer_text: str = None, footer_icon_url: str = None):
1011+
await ctx.send("Embed Built!", hidden=True)
1012+
await ctx.channel.send(embed=framework.isobot.embedengine.embed(title, description, image=image_url, thumbnail=thumbnail_url, color=color, footer_text=footer_text, footer_img=footer_icon_url))
1013+
9961014
@slash.slash(
9971015
name="isobank_register",
9981016
description="Registers a new IsoBank account with your Discord ID",

0 commit comments

Comments
 (0)