|
| 1 | +import re |
| 2 | + |
| 3 | +import discord |
| 4 | +from discord.errors import Forbidden |
| 5 | + |
| 6 | +# color scheme for embeds as rbg |
| 7 | +yellow = (245, 218, 17) # waring like 'hey, that's not cool' |
| 8 | +orange = (245, 139, 17) # waring - rather critical like 'no more votes left' |
| 9 | + |
| 10 | + |
| 11 | +async def send_embed(ctx, embed): |
| 12 | + """ |
| 13 | + Handles the sending of embeds |
| 14 | + -> Takes context and embed to send |
| 15 | + - tries to send embed in channel |
| 16 | + - tries to send normal message when that fails |
| 17 | + - tries to send embed private with information abot missing permissions |
| 18 | + If this all fails: https://youtu.be/dQw4w9WgXcQ |
| 19 | + """ |
| 20 | + try: |
| 21 | + await ctx.send(embed=embed) |
| 22 | + except Forbidden: |
| 23 | + try: |
| 24 | + await ctx.send("Hey, seems like I can't send embeds. Please check my permissions :)") |
| 25 | + except Forbidden: |
| 26 | + await ctx.author.send( |
| 27 | + f"Hey, seems like I can't send any message in {ctx.channel.name} on {ctx.guild.name}\n" |
| 28 | + f"May you inform the server team about this issue? :slight_smile:", embed=embed) |
| 29 | + |
| 30 | + |
| 31 | +# creating and returning an embed with keyword arguments |
| 32 | +# please note that name and value can't be empty - name and value contain a zero width non-joiner |
| 33 | +def make_embed(title="", color=(20, 255, 255), name="", value="", footer=None) -> discord.Embed: |
| 34 | + """ |
| 35 | + Function to generate generate an embed in one function call |
| 36 | +
|
| 37 | + :param title: Headline of embed |
| 38 | + :param color: RGB Tuple (Red, Green, Blue) |
| 39 | + :param name: Of field (sub-headline) |
| 40 | + :param value: Text of field (actual text) |
| 41 | + :param footer: Text in footer |
| 42 | + :return: Embed ready to send |
| 43 | + """ |
| 44 | + # make color object |
| 45 | + color = discord.Color.from_rgb(*color) # * unwraps the elements in the tuple |
| 46 | + emb = discord.Embed(title=title, color=color) |
| 47 | + emb.add_field(name=name, value=value) |
| 48 | + if footer: |
| 49 | + emb.set_footer(text=footer) |
| 50 | + |
| 51 | + return emb |
0 commit comments