Created
August 2, 2018 17:04
-
-
Save jffz/598b8b53c352e77f1e7f370bae065c36 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from discord.ext import commands | |
import discord | |
def build_embed(ctx, **kwargs): | |
# Set default parameters | |
parameters = { | |
'author_avatar_url': ctx.author.avatar_url, | |
'author_name': ctx.author.name, | |
'author_url': ctx.author.url, | |
'colour': discord.Colour.default(), | |
'img_url': None, | |
'footer_text': None, | |
'footer_icon': None, | |
'title': 'Title', | |
'description': 'Description', | |
'content': '' | |
} | |
# Replace defaults parameters with args | |
for parameter in parameters.items(): | |
if parameter in kwargs: | |
parameters[parameter] = kwargs.pop(parameter) | |
# Create embed with basics parameters | |
embed = discord.Embed( | |
title = parameters['title'], | |
description = parameters['description'], | |
colour = parameters['colour'] | |
) | |
# set embed author | |
embed.set_author( | |
icon_url=parameters['author_avatar_url'], | |
name=parameters['author_name'], | |
url=parameters['author_url'] | |
) | |
# Set remaining args as fields | |
if kwargs: | |
for k, v in kwargs: | |
embed.add_field(name=k, value=v, inline=True) | |
# Set embed img if set | |
if parameters['img_url']: | |
embed.set_image(url=parameters['img_url']) | |
# Define footer if args set | |
if parameters['footer_text'] or parameters['footer_icon']: | |
embed.set_footer( | |
text=parameters['footer_text'], icon_url=parameters['footer_icon'] | |
) | |
return parameters['content'], embed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment