Skip to content

Commit

Permalink
Merge pull request #12 from renaism/develop
Browse files Browse the repository at this point in the history
feat: ytthumbnail command
  • Loading branch information
renaism authored Oct 3, 2023
2 parents 06bb893 + 8dd1d25 commit 42e4b6f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/cogs/utility.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import config
import discord
import re

from ..helper import get_member_voice_channel

Expand Down Expand Up @@ -91,6 +92,28 @@ async def vcmention(self, ctx: discord.ApplicationContext):
if vc_mem != member)

return await ctx.respond(f"**{member.display_name}**: {mentions}")


@discord.slash_command(
description="Get the direct link for a youtube video thumbnail image."
)
async def ytthumbnail(self, ctx: discord.ApplicationContext, link: str):
# Parse video id from link
match = re.search(r"(?:youtube.com\/watch\?v=|youtu.be\/)([0-9A-Za-z_-]{11}).*", link)

if not match:
await ctx.respond(
"The link is not a valid YouTube video URL!",
ephemeral=True,
delete_after=config.BotConfig.EPHEMERAL_MSG_DURATION
)

return

video_id = match.group(1)
thumbnail_url = f"https://img.youtube.com/vi/{video_id}/maxresdefault.jpg"

await ctx.respond(thumbnail_url)


def setup(bot: discord.Bot):
Expand Down

0 comments on commit 42e4b6f

Please sign in to comment.