Create create_embed template to replace discord.Embed()

- Auto-set color to BOT_COLOR
- Set footer to timestamp (overridden is timestamp is passed)
- Optional thumbnail
This commit is contained in:
Parker M. 2024-11-28 00:41:33 -06:00
parent 1ce91a4b09
commit e73db927c1
Signed by: parker
GPG Key ID: 505ED36FC12B5D5E
21 changed files with 147 additions and 349 deletions

View File

@ -6,7 +6,7 @@ from cogs.music import Music
from typing import Literal
from utils.ai_recommendations import add_song_recommendations
from utils.config import BOT_COLOR
from utils.config import create_embed
class Autoplay(commands.Cog):
@ -23,28 +23,26 @@ class Autoplay(commands.Cog):
if toggle == "OFF":
self.bot.autoplay.remove(interaction.guild.id)
embed = discord.Embed(
embed = create_embed(
title="Autoplay Off",
description=(
"Autoplay has been turned off. I will no longer"
" automatically add new songs to the queue based on AI"
" recommendations."
),
color=BOT_COLOR,
)
return await interaction.response.send_message(embed=embed)
# Otherwise, toggle must be "ON", so enable autoplaying
if interaction.guild.id in self.bot.autoplay:
embed = discord.Embed(
embed = create_embed(
title="Autoplay Already Enabled",
description=(
"Autoplay is already enabled. If you would like to turn it"
" off, choose the `OFF` option in the"
" </autoplay:1228216490386391052> command."
),
color=BOT_COLOR,
)
return await interaction.response.send_message(
embed=embed, ephemeral=True
@ -53,7 +51,7 @@ class Autoplay(commands.Cog):
player = self.bot.lavalink.player_manager.get(interaction.guild.id)
if len(player.queue) < 5:
embed = discord.Embed(
embed = create_embed(
title="Not Enough Context",
description=(
"You must have at least 5 songs in the queue so that I can"
@ -61,13 +59,6 @@ class Autoplay(commands.Cog):
" to play. Add some more music to the queue, then try"
" again."
),
color=BOT_COLOR,
)
embed.set_footer(
text=datetime.datetime.now(datetime.timezone.utc).strftime(
"%Y-%m-%d %H:%M:%S"
)
+ " UTC"
)
return await interaction.response.send_message(
embed=embed, ephemeral=True
@ -77,13 +68,12 @@ class Autoplay(commands.Cog):
for song in player.queue[:10]:
inputs[song.title] = song.author
embed = discord.Embed(
embed = create_embed(
title="Getting AI Recommendations",
description=(
"Attempting to generate recommendations based on the current"
" songs in your queue. Just a moment..."
),
color=BOT_COLOR,
)
await interaction.response.send_message(embed=embed)
@ -91,7 +81,7 @@ class Autoplay(commands.Cog):
self.bot.openai, self.bot.user, player, 5, inputs
):
self.bot.autoplay.append(interaction.guild.id)
embed = discord.Embed(
embed = create_embed(
title=":infinity: Autoplay Enabled :infinity:",
description=(
"I have added a few similar songs to the queue and will"
@ -99,12 +89,11 @@ class Autoplay(commands.Cog):
" just sit back and enjoy the music!\n\nEnabled by:"
f" {interaction.user.mention}"
),
color=BOT_COLOR,
)
await interaction.edit_original_response(embed=embed)
else:
embed = discord.Embed(
embed = create_embed(
title="Autoplay Error",
description=(
"Autoplay is an experimental feature, meaning sometimes it"
@ -113,13 +102,6 @@ class Autoplay(commands.Cog):
" command again. If the issue persists, fill out a bug"
" report with the </bug:1224840889906499626> command."
),
color=BOT_COLOR,
)
embed.set_footer(
text=datetime.datetime.now(datetime.timezone.utc).strftime(
"%Y-%m-%d %H:%M:%S"
)
+ " UTC"
)
await interaction.edit_original_response(embed=embed)

View File

@ -4,7 +4,7 @@ from discord import app_commands
from discord.ext import commands
from cogs.music import Music
from utils.config import BOT_COLOR
from utils.config import create_embed
class Clear(commands.Cog):
@ -18,19 +18,13 @@ class Clear(commands.Cog):
player = self.bot.lavalink.player_manager.get(interaction.guild.id)
player.queue.clear()
embed = discord.Embed(
embed = create_embed(
title="Queue Cleared",
description=(
"The queue has been cleared of all songs!\n\nIssued by:"
f" {interaction.user.mention}"
),
color=BOT_COLOR,
)
embed.set_footer(
text=datetime.datetime.now(datetime.timezone.utc).strftime(
"%Y-%m-%d %H:%M:%S"
)
+ " UTC"
)
await interaction.response.send_message(embed=embed)

View File

@ -4,7 +4,7 @@ from discord import app_commands
from discord.ext import commands
from cogs.music import Music
from utils.config import BOT_COLOR
from utils.config import create_embed
class Lyrics(commands.Cog):
@ -19,19 +19,12 @@ class Lyrics(commands.Cog):
# If the Genius API client is not setup, send an error message
if not self.bot.genius:
embed = discord.Embed(
embed = create_embed(
title="Lyrics Feature Error",
description=(
"The lyrics feature is currently disabled due to errors"
" with the Genius API."
),
color=BOT_COLOR,
)
embed.set_footer(
text=datetime.datetime.now(datetime.timezone.utc).strftime(
"%Y-%m-%d %H:%M:%S"
)
+ " UTC"
)
return await interaction.response.send_message(
embed=embed, ephemeral=True
@ -48,20 +41,13 @@ class Lyrics(commands.Cog):
# If no lyrics are found, send an error message
if song is None:
embed = discord.Embed(
embed = create_embed(
title="Lyrics Not Found",
description=(
"Unfortunately, I wasn't able to find any lyrics for the"
" song that is currently playing."
),
color=BOT_COLOR,
)
embed.set_thumbnail(url=player.current.artwork_url)
embed.set_footer(
text=datetime.datetime.now(datetime.timezone.utc).strftime(
"%Y-%m-%d %H:%M:%S"
)
+ " UTC"
thumbnail=player.current.artwork_url,
)
return await interaction.edit_original_response(embed=embed)
@ -73,7 +59,7 @@ class Lyrics(commands.Cog):
# If the lyrics are too long, send just a link to the lyrics
if len(lyrics) > 2048:
embed = discord.Embed(
embed = create_embed(
title=(
f"Lyrics for {player.current.title} by"
f" {player.current.author}"
@ -82,31 +68,17 @@ class Lyrics(commands.Cog):
"Song lyrics are too long to display on Discord. [Click"
f" here to view the lyrics on Genius]({song.url})."
),
color=BOT_COLOR,
)
embed.set_thumbnail(url=player.current.artwork_url)
embed.set_footer(
text=datetime.datetime.now(datetime.timezone.utc).strftime(
"%Y-%m-%d %H:%M:%S"
)
+ " UTC"
thumbnail=player.current.artwork_url,
)
return await interaction.edit_original_response(embed=embed)
# If everything is successful, send the lyrics
embed = discord.Embed(
embed = create_embed(
title=(
f"Lyrics for {player.current.title} by {player.current.author}"
),
description=f"Provided from [Genius]({song.url})\n\n" + lyrics,
color=BOT_COLOR,
)
embed.set_thumbnail(url=player.current.artwork_url)
embed.set_footer(
text=datetime.datetime.now(datetime.timezone.utc).strftime(
"%Y-%m-%d %H:%M:%S"
)
+ " UTC"
thumbnail=player.current.artwork_url,
)
await interaction.edit_original_response(embed=embed)

View File

@ -5,7 +5,7 @@ from discord.ext import commands
from cogs.music import Music
import lavalink
from utils.config import BOT_COLOR
from utils.config import create_embed
class NowPlaying(commands.Cog):
@ -25,21 +25,14 @@ class NowPlaying(commands.Cog):
time_in = time_in[2:]
total_duration = total_duration[3:]
embed = discord.Embed(
embed = create_embed(
title="Now Playing 🎶",
description=(
f"**[{player.current.title}]({player.current.uri})** by"
f" {player.current.author}\n{f'` {time_in}/{total_duration} `'}\n\nQueued"
f" by: {player.current.requester.mention}"
),
color=BOT_COLOR,
)
embed.set_thumbnail(url=player.current.artwork_url)
embed.set_footer(
text=datetime.datetime.now(datetime.timezone.utc).strftime(
"%Y-%m-%d %H:%M:%S"
)
+ " UTC"
thumbnail=player.current.artwork_url,
)
await interaction.response.send_message(embed=embed)

View File

@ -4,7 +4,7 @@ from discord import app_commands
from discord.ext import commands
from cogs.music import Music
from utils.config import BOT_COLOR
from utils.config import create_embed
class Pause(commands.Cog):
@ -18,20 +18,13 @@ class Pause(commands.Cog):
player = self.bot.lavalink.player_manager.get(interaction.guild.id)
await player.set_pause(pause=True)
embed = discord.Embed(
embed = create_embed(
title=f"Music Now Paused ⏸️",
description=(
f"**[{player.current.title}]({player.current.uri})**\n\nQueued"
f" by: {player.current.requester.mention}"
),
color=BOT_COLOR,
)
embed.set_thumbnail(url=player.current.artwork_url)
embed.set_footer(
text=datetime.datetime.now(datetime.timezone.utc).strftime(
"%Y-%m-%d %H:%M:%S"
)
+ " UTC"
thumbnail=player.current.artwork_url,
)
await interaction.response.send_message(embed=embed)

View File

@ -6,7 +6,7 @@ from lavalink import LoadType
import re
from cogs.music import Music, LavalinkVoiceClient
from utils.config import BOT_COLOR, YOUTUBE_SUPPORT
from utils.config import YOUTUBE_SUPPORT, create_embed
from utils.custom_sources import (
LoadError,
CustomAudioTrack,
@ -31,7 +31,7 @@ class Play(commands.Cog):
# Notify users that YouTube links are not allowed if YouTube support is disabled
if "youtube.com" in query or "youtu.be" in query:
if not YOUTUBE_SUPPORT:
embed = discord.Embed(
embed = create_embed(
title="YouTube Not Supported",
description=(
"Unfortunately, YouTube does not allow bots to stream"
@ -40,7 +40,6 @@ class Play(commands.Cog):
" song and I will automatically find it on a supported"
" platform."
),
color=BOT_COLOR,
)
return await interaction.response.send_message(
embed=embed, ephemeral=True
@ -91,54 +90,39 @@ class Play(commands.Cog):
# Create the embed if the results are a playlist
if results.load_type == LoadType.PLAYLIST:
embed = discord.Embed(
embed = create_embed(
title="Songs Queued!",
description=(
f"**{results.playlist_info.name}**\n"
f"` {len(results.tracks)} ` tracks\n\n"
f"Queued by: {interaction.user.mention}"
),
color=BOT_COLOR,
)
embed.set_footer(
text=datetime.datetime.utcnow().strftime(
"%Y-%m-%d %H:%M:%S"
)
+ " UTC"
)
await interaction.response.send_message(embed=embed)
# Otherwise, the result is just a single track, create that embed
else:
# Remove all but first track (most relevant result)
results.tracks = results.tracks[:1]
embed = discord.Embed(
embed = create_embed(
title="Song Queued!",
description=(
f"**{results.tracks[0].title}** by"
f" **{results.tracks[0].author}**\n\nQueued by:"
f" {interaction.user.mention}"
),
color=BOT_COLOR,
)
embed.set_thumbnail(url=results.tracks[0].artwork_url)
embed.set_footer(
text=datetime.datetime.utcnow().strftime(
"%Y-%m-%d %H:%M:%S"
)
+ " UTC"
thumbnail=results.tracks[0].artwork_url,
)
await interaction.response.send_message(embed=embed)
# If there are no results, and no embed
if not results and not embed:
embed = discord.Embed(
embed = create_embed(
title="Nothing Found",
description=(
"I was not able to find or load any songs for that query."
" Please try again and fill out a bug report with"
" </bug:1224840889906499626> if this continues to happen."
),
color=BOT_COLOR,
)
return await interaction.response.send_message(
embed=embed, ephemeral=True

View File

@ -6,7 +6,7 @@ from cogs.music import Music
import math
import lavalink
from utils.config import BOT_COLOR
from utils.config import create_embed
class Queue(commands.Cog):
@ -23,19 +23,12 @@ class Queue(commands.Cog):
player = self.bot.lavalink.player_manager.get(interaction.guild.id)
if not player.queue:
embed = discord.Embed(
embed = create_embed(
title="Nothing Queued",
description=(
"Nothing is currently in the queue, add a song with the"
" </play:1224840890368000172> command."
),
color=BOT_COLOR,
)
embed.set_footer(
text=datetime.datetime.now(datetime.timezone.utc).strftime(
"%Y-%m-%d %H:%M:%S"
)
+ " UTC"
)
return await interaction.response.send_message(
embed=embed, ephemeral=True
@ -60,14 +53,13 @@ class Queue(commands.Cog):
f" {track.author} `({track_duration})`\n"
)
embed = discord.Embed(
embed = create_embed(
title=f"Queue for {interaction.guild.name}",
description=(
f"**{len(player.queue)} tracks total**\n\n{queue_list}"
),
color=BOT_COLOR,
footer=f"Viewing page {page}/{pages}",
)
embed.set_footer(text=f"Viewing page {page}/{pages}")
await interaction.response.send_message(embed=embed)

View File

@ -4,7 +4,7 @@ from discord import app_commands
from discord.ext import commands
from cogs.music import Music
from utils.config import BOT_COLOR
from utils.config import create_embed
class Remove(commands.Cog):
@ -19,26 +19,15 @@ class Remove(commands.Cog):
player = self.bot.lavalink.player_manager.get(interaction.guild.id)
if not player.queue:
embed = discord.Embed(
embed = create_embed(
title="Nothing Queued",
description=(
"Nothing is currently in the queue, so there is nothing"
" for me to remove."
),
color=BOT_COLOR,
)
embed.set_footer(
text=datetime.datetime.now(datetime.timezone.utc).strftime(
"%Y-%m-%d %H:%M:%S"
)
+ " UTC"
description="There are no songs in the queue to remove.",
)
return await interaction.response.send_message(embed=embed)
if number > len(player.queue) or number < 1:
return await interaction.response.send_message(
"The number entered is not a number within the queue - please"
" try again!",
"Number out of range - please try again!",
ephemeral=True,
)
@ -48,21 +37,14 @@ class Remove(commands.Cog):
removed_artwork = player.queue[index].artwork_url
player.queue.pop(index)
embed = discord.Embed(
embed = create_embed(
title="Song Removed from Queue",
description=(
"**Song Removed -"
f" [{removed_title}]({removed_url})**\n\nIssued by:"
f" {interaction.user.mention}"
),
color=BOT_COLOR,
)
embed.set_thumbnail(url=removed_artwork)
embed.set_footer(
text=datetime.datetime.now(datetime.timezone.utc).strftime(
"%Y-%m-%d %H:%M:%S"
)
+ " UTC"
thumbnail=removed_artwork,
)
await interaction.response.send_message(embed=embed)

View File

@ -4,7 +4,7 @@ from discord import app_commands
from discord.ext import commands
from cogs.music import Music
from utils.config import BOT_COLOR
from utils.config import create_embed
class Repeat(commands.GroupCog, name="repeat"):
@ -18,16 +18,9 @@ class Repeat(commands.GroupCog, name="repeat"):
player = self.bot.lavalink.player_manager.get(interaction.guild.id)
if player.loop == 0:
embed = discord.Embed(
title=f"Repeating Already Off",
description=f"Music repetition is already turned off.",
color=BOT_COLOR,
)
embed.set_footer(
text=datetime.datetime.now(datetime.timezone.utc).strftime(
"%Y-%m-%d %H:%M:%S"
)
+ " UTC"
embed = create_embed(
title="Repeating Already Off",
description="Music repetition is already turned off.",
)
return await interaction.response.send_message(
embed=embed, ephemeral=True
@ -35,16 +28,9 @@ class Repeat(commands.GroupCog, name="repeat"):
player.loop = 0
embed = discord.Embed(
title=f"Repeating Off",
description=f"Music will no longer be repeated.",
color=BOT_COLOR,
)
embed.set_footer(
text=datetime.datetime.now(datetime.timezone.utc).strftime(
"%Y-%m-%d %H:%M:%S"
)
+ " UTC"
embed = create_embed(
title="Repeating Off",
description="Music will no longer be repeated.",
)
await interaction.response.send_message(embed=embed)
@ -55,36 +41,21 @@ class Repeat(commands.GroupCog, name="repeat"):
player = self.bot.lavalink.player_manager.get(interaction.guild.id)
if player.loop == 1:
embed = discord.Embed(
title=f"Repeating Already On",
description=f"The current song is already being repeated.",
color=BOT_COLOR,
)
embed.set_footer(
text=datetime.datetime.now(datetime.timezone.utc).strftime(
"%Y-%m-%d %H:%M:%S"
)
+ " UTC"
embed = create_embed(
title="Repeating Already On",
description="The current song is already being repeated.",
)
return await interaction.response.send_message(
embed=embed, ephemeral=True
)
player.loop = 1
embed = discord.Embed(
title=f"Repeating Current Song 🔁",
embed = create_embed(
title="Repeating Current Song 🔁",
description=(
f"The song that is currently playing will be repeated until"
f" the </repeat off:1224840891395608737> command is run"
"The song that is currently playing will be repeated until"
" the </repeat off:1224840891395608737> command is run"
),
color=BOT_COLOR,
)
embed.set_footer(
text=datetime.datetime.now(datetime.timezone.utc).strftime(
"%Y-%m-%d %H:%M:%S"
)
+ " UTC"
)
await interaction.response.send_message(embed=embed)
@ -95,36 +66,21 @@ class Repeat(commands.GroupCog, name="repeat"):
player = self.bot.lavalink.player_manager.get(interaction.guild.id)
if player.loop == 2:
embed = discord.Embed(
title=f"Repeating Already On",
description=f"The queue is already being repeated.",
color=BOT_COLOR,
)
embed.set_footer(
text=datetime.datetime.now(datetime.timezone.utc).strftime(
"%Y-%m-%d %H:%M:%S"
)
+ " UTC"
embed = create_embed(
title="Repeating Already On",
description="The queue is already being repeated.",
)
return await interaction.response.send_message(
embed=embed, ephemeral=True
)
player.loop = 2
embed = discord.Embed(
title=f"Repeating Current Song 🔂",
embed = create_embed(
title="Repeating Queue 🔂",
description=(
f"All songs in the queue will continue to repeat until the"
f" </repeat off:1224840891395608737> command is run."
"The queue will continuously repeat until the"
" </repeat off:1224840891395608737> command is run."
),
color=BOT_COLOR,
)
embed.set_footer(
text=datetime.datetime.now(datetime.timezone.utc).strftime(
"%Y-%m-%d %H:%M:%S"
)
+ " UTC"
)
await interaction.response.send_message(embed=embed)

View File

@ -4,7 +4,7 @@ from discord import app_commands
from discord.ext import commands
from cogs.music import Music
from utils.config import BOT_COLOR
from utils.config import create_embed
class Resume(commands.Cog):
@ -18,20 +18,13 @@ class Resume(commands.Cog):
player = self.bot.lavalink.player_manager.get(interaction.guild.id)
await player.set_pause(pause=False)
embed = discord.Embed(
embed = create_embed(
title=f"Music Now Resumed ⏯️",
description=(
f"**[{player.current.title}]({player.current.uri})**\n\nQueued"
f" by: {player.current.requester.mention}"
),
color=BOT_COLOR,
)
embed.set_thumbnail(url=player.current.artwork_url)
embed.set_footer(
text=datetime.datetime.now(datetime.timezone.utc).strftime(
"%Y-%m-%d %H:%M:%S"
)
+ " UTC"
thumbnail=player.current.artwork_url,
)
await interaction.response.send_message(embed=embed)

View File

@ -4,7 +4,7 @@ from discord import app_commands
from discord.ext import commands
from cogs.music import Music
from utils.config import BOT_COLOR
from utils.config import create_embed
class Shuffle(commands.GroupCog, name="shuffle"):
@ -19,16 +19,9 @@ class Shuffle(commands.GroupCog, name="shuffle"):
player.shuffle = True
embed = discord.Embed(
title=f"Shuffle Enabled 🔀",
description=f"All music will now be shuffled.",
color=BOT_COLOR,
)
embed.set_footer(
text=datetime.datetime.now(datetime.timezone.utc).strftime(
"%Y-%m-%d %H:%M:%S"
)
+ " UTC"
embed = create_embed(
title="Shuffle Enabled 🔀",
description="All music will now be shuffled.",
)
await interaction.response.send_message(embed=embed)
@ -40,16 +33,9 @@ class Shuffle(commands.GroupCog, name="shuffle"):
player.shuffle = False
embed = discord.Embed(
title=f"Disabled 🔀",
description=f"Music will no longer be shuffled.",
color=BOT_COLOR,
)
embed.set_footer(
text=datetime.datetime.now(datetime.timezone.utc).strftime(
"%Y-%m-%d %H:%M:%S"
)
+ " UTC"
embed = create_embed(
title="Shuffle Disabled 🔀",
description="Music will no longer be shuffled.",
)
await interaction.response.send_message(embed=embed)

View File

@ -5,7 +5,7 @@ from discord.ext import commands
from cogs.music import Music
import asyncio
from utils.config import BOT_COLOR
from utils.config import create_embed
from utils.custom_sources import LoadError
@ -22,22 +22,25 @@ class Skip(commands.Cog):
"Skips the song that is currently playing"
player = self.bot.lavalink.player_manager.get(interaction.guild.id)
embed = discord.Embed(color=BOT_COLOR)
if number != 1:
if number < 1:
embed.title = "Invalid Number"
embed.description = "The number option cannot be less than 1"
embed = create_embed(
title="Invalid Number",
description="The number option cannot be less than 1",
)
return await interaction.response.send_message(
embed=embed, ephemeral=True
)
elif number > len(player.queue):
embed.title = "Number too Large"
embed.description = (
"The number you entered is larger than the number of songs"
" in queue. If you want to stop playing music entirely,"
" try the </stop:1224840890866991305> command."
embed = create_embed(
title="Number too Large",
description=(
"The number you entered is larger than the number of"
" songs in queue. If you want to stop playing music"
" entirely, try the </stop:1224840890866991305>"
" command."
),
)
return await interaction.response.send_message(
embed=embed, ephemeral=True
@ -53,14 +56,13 @@ class Skip(commands.Cog):
# If the song is on repeat, catch the IndexError and get the current song
# Otherwise, pass
if player.loop == 1:
embed = discord.Embed(
embed = create_embed(
title="Song on Repeat",
description=(
"There is nothing in queue, but the current song is on"
" repeat. Use </stop:1224840890866991305> to stop"
" playing music."
),
color=BOT_COLOR,
)
return await interaction.response.send_message(
embed=embed, ephemeral=True
@ -77,34 +79,26 @@ class Skip(commands.Cog):
await player.skip()
if not player.current:
embed = discord.Embed(
embed = create_embed(
title="End of Queue",
description=(
"All songs in queue have been played. Thank you for using"
f" me :wave:\n\nIssued by: {interaction.user.mention}"
),
color=BOT_COLOR,
)
return await interaction.response.send_message(embed=embed)
# It takes a sec for the new track to be grabbed and played
# So just wait a sec before sending the message
await asyncio.sleep(0.5)
embed = discord.Embed(
embed = create_embed(
title="Track Skipped",
description=(
f"**Now Playing: [{next_song.title}]({next_song.uri})** by"
f" {next_song.author}\n\nQueued by:"
f" {next_song.requester.mention}"
),
color=BOT_COLOR,
)
embed.set_thumbnail(url=next_song.artwork_url)
embed.set_footer(
text=datetime.datetime.now(datetime.timezone.utc).strftime(
"%Y-%m-%d %H:%M:%S"
)
+ " UTC"
thumbnail=next_song.artwork_url,
)
await interaction.response.send_message(embed=embed)

View File

@ -4,7 +4,7 @@ from discord import app_commands
from discord.ext import commands
from cogs.music import Music
from utils.config import BOT_COLOR
from utils.config import create_embed
class Stop(commands.Cog):
@ -25,19 +25,12 @@ class Stop(commands.Cog):
await player.stop()
await interaction.guild.voice_client.disconnect(force=True)
embed = discord.Embed(
embed = create_embed(
title="Queue Cleared and Music Stopped",
description=(
"Thank you for using me :wave:\n\nIssued by:"
f" {interaction.user.mention}"
),
color=BOT_COLOR,
)
embed.set_footer(
text=datetime.datetime.now(datetime.timezone.utc).strftime(
"%Y-%m-%d %H:%M:%S"
)
+ " UTC"
)
await interaction.response.send_message(embed=embed)

View File

@ -1,9 +1,8 @@
import discord
from discord import app_commands
from discord.ext.commands.errors import *
import datetime
from utils.config import BOT_COLOR
from utils.config import create_embed
from utils.custom_sources import LoadError
@ -38,16 +37,9 @@ class Tree(app_commands.CommandTree):
# Custom Error class for the `create_player` function
# Issues that arise may be user not in vc, user not in correct vc, missing perms, etc.
elif isinstance(error, CheckPlayerError):
embed = discord.Embed(
embed = create_embed(
title=error.info["title"],
description=error.info["description"],
color=BOT_COLOR,
)
embed.set_footer(
text=datetime.datetime.now(datetime.timezone.utc).strftime(
"%Y-%m-%d %H:%M:%S"
)
+ " UTC"
)
try:
await interaction.response.send_message(
@ -62,20 +54,13 @@ class Tree(app_commands.CommandTree):
isinstance(error, app_commands.CheckFailure)
and interaction.command.name in music_commands
):
embed = discord.Embed(
embed = create_embed(
title="Player Creation Error",
description=(
"An error occured when trying to create a player. Please"
" submit a bug report with </bug:1224840889906499626> if"
" this issue persists."
),
color=BOT_COLOR,
)
embed.set_footer(
text=datetime.datetime.now(datetime.timezone.utc).strftime(
"%Y-%m-%d %H:%M:%S"
)
+ " UTC"
)
try:
await interaction.response.send_message(
@ -85,14 +70,13 @@ class Tree(app_commands.CommandTree):
await interaction.followup.send(embed=embed, ephemeral=True)
elif (error, LoadError):
embed = discord.Embed(
embed = create_embed(
title="Load Error",
description=(
"Apple Music and Spotify do not allow direct playing from"
" their websites, and I was unable to load a track on a"
" valid source. Please try again."
),
color=BOT_COLOR,
)
# Only send the error if the interaction is still valid
try:

View File

@ -8,6 +8,7 @@ import sys
import discord
import logging
import requests
from datetime import datetime
from colorlog import ColoredFormatter
log_level = logging.DEBUG
@ -274,3 +275,30 @@ def validate_config(file_contents):
LAVALINK_HOST = config["lavalink"]["host"]
LAVALINK_PORT = config["lavalink"]["port"]
LAVALINK_PASSWORD = config["lavalink"]["password"]
"""
Template for embeds
"""
def create_embed(
title: str, description: str, color=None, footer=None, thumbnail=None
):
embed = discord.Embed(
title=title,
description=description,
color=color if color else BOT_COLOR,
)
if footer:
embed.set_footer(text=footer)
else:
embed.set_footer(
text=datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S") + " UTC"
)
if thumbnail:
embed.set_thumbnail(url=thumbnail)
return embed

View File

@ -4,7 +4,7 @@ import requests
from typing import Tuple, Optional
from requests.exceptions import JSONDecodeError
from utils.config import BOT_COLOR, LOG
from utils.config import create_embed, LOG
async def load(
@ -25,13 +25,12 @@ async def load(
)
if response.status_code == 404:
embed = discord.Embed(
embed = create_embed(
title="Album Not Found",
description=(
"The album could not be found as the provided link is"
" invalid. Please try again."
),
color=BOT_COLOR,
)
return None, embed
@ -62,18 +61,14 @@ async def load(
if artwork_url:
artwork_url = artwork_url.replace("{w}x{h}", "300x300")
embed = discord.Embed(
embed = create_embed(
title="Album Queued",
description=(
f"**{name}** by **{artist}**\n"
f"` {num_tracks} ` tracks\n\n"
f"Queued by: {user.mention}"
),
color=BOT_COLOR,
)
embed.set_thumbnail(url=artwork_url)
embed.set_footer(
text=datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S") + " UTC"
thumbnail=artwork_url,
)
return album, embed

View File

@ -1,10 +1,9 @@
import datetime
import discord
import requests
from typing import Tuple, Optional
from requests.exceptions import JSONDecodeError
from utils.config import BOT_COLOR, LOG
from utils.config import create_embed, LOG
async def load(
@ -24,13 +23,12 @@ async def load(
)
if response.status_code == 404:
embed = discord.Embed(
embed = create_embed(
title="Playlist Not Found",
description=(
"The playlist could not be found as the provided link is"
" invalid. Please try again."
),
color=BOT_COLOR,
)
return None, embed
@ -71,12 +69,12 @@ async def load(
if artwork_url:
artwork_url = artwork_url.replace("{w}x{h}", "300x300")
embed = discord.Embed(
embed = create_embed(
title="Playlist Queued",
description=(
f"**{name}**\n` {num_tracks} ` tracks\n\nQueued by: {user.mention}"
),
color=BOT_COLOR,
thumbnail=artwork_url,
)
# Add small alert if the playlist is the max size

View File

@ -1,10 +1,9 @@
import datetime
import discord
import requests
from typing import Tuple, Optional
from requests.exceptions import JSONDecodeError
from utils.config import BOT_COLOR, LOG
from utils.config import create_embed, LOG
async def load(
@ -25,13 +24,12 @@ async def load(
)
if response.status_code == 404:
embed = discord.Embed(
embed = create_embed(
title="Song Not Found",
description=(
"The song could not be found as the provided link is"
" invalid. Please try again."
),
color=BOT_COLOR,
)
return None, embed
@ -61,14 +59,10 @@ async def load(
if artwork_url:
artwork_url = artwork_url.replace("{w}x{h}", "300x300")
embed = discord.Embed(
embed = create_embed(
title="Song Queued",
description=f"**{name}** by **{artist}**\n\nQueued by: {user.mention}",
color=BOT_COLOR,
)
embed.set_thumbnail(url=artwork_url)
embed.set_footer(
text=datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S") + " UTC"
description=f"**{name}** by **{artist}**\n\nQueued by {user.mention}",
thumbnail=artwork_url,
)
return song, embed

View File

@ -4,7 +4,7 @@ import requests
from typing import Tuple, Optional
from requests.exceptions import JSONDecodeError
from utils.config import BOT_COLOR, LOG
from utils.config import create_embed, LOG
async def load(
@ -25,13 +25,12 @@ async def load(
)
if response.status_code == 404:
embed = discord.Embed(
embed = create_embed(
title="Album Not Found",
description=(
"The album could not be found as the provided link is"
" invalid. Please try again."
),
color=BOT_COLOR,
)
return None, embed
@ -56,18 +55,14 @@ async def load(
LOG.error("Failed making request to Spotify API")
return None, None
embed = discord.Embed(
embed = create_embed(
title="Album Queued",
description=(
f"**{name}** by **{artist}**\n"
f"` {num_tracks} ` tracks\n\n"
f"Queued by: {user.mention}"
),
color=BOT_COLOR,
)
embed.set_thumbnail(url=artwork_url)
embed.set_footer(
text=datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S") + " UTC"
thumbnail=artwork_url,
)
return album, embed

View File

@ -4,7 +4,7 @@ import requests
from typing import Tuple, Optional
from requests.exceptions import JSONDecodeError
from utils.config import BOT_COLOR, LOG
from utils.config import create_embed, LOG
async def load(
@ -25,13 +25,12 @@ async def load(
)
if response.status_code == 404:
embed = discord.Embed(
embed = create_embed(
title="Playlist Not Found",
description=(
"The playlist could not be found as the provided link is"
" invalid. Please try again."
),
color=BOT_COLOR,
)
return None, embed
@ -56,18 +55,14 @@ async def load(
LOG.error("Failed making request to Spotify API")
return None, None
embed = discord.Embed(
embed = create_embed(
title="Playlist Queued",
description=(
f"**{name}** from **{owner}**\n"
f"` {num_tracks} ` tracks\n\n"
f"Queued by {user.mention}"
),
color=BOT_COLOR,
)
embed.set_thumbnail(url=artwork_url)
embed.set_footer(
text=datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S") + " UTC"
thumbnail=artwork_url,
)
return playlist, embed

View File

@ -4,7 +4,7 @@ import requests
from typing import Tuple, Optional
from requests.exceptions import JSONDecodeError
from utils.config import BOT_COLOR, LOG
from utils.config import create_embed, LOG
async def load(
@ -25,13 +25,12 @@ async def load(
)
if response.status_code == 404:
embed = discord.Embed(
embed = create_embed(
title="Song Not Found",
description=(
"The song could not be found as the provided link is"
" invalid. Please try again."
),
color=BOT_COLOR,
)
return None, embed
@ -55,14 +54,10 @@ async def load(
LOG.error("Failed making request to Spotify API")
return None, None
embed = discord.Embed(
embed = create_embed(
title="Song Queued",
description=f"**{name}** by **{artist}**\n\nQueued by {user.mention}",
color=BOT_COLOR,
)
embed.set_thumbnail(url=artwork_url)
embed.set_footer(
text=datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S") + " UTC"
thumbnail=artwork_url,
)
return song, embed