mardi 5 janvier 2021

How can I generate a random Youtube link without using Youtube API in Discord.py

I am creating a discord bot and using python and I want it to be able to generate a random or pseudo-random youtube link. Most people use youtube API for this, but I am limited on what I could insert into my bot. What I did was generate a random 11 character alphanumeric string and insert it into a partial youtube URL. The only problem is that nearly every link generated doesn't exist. Would there be a way to loop the link generation until it finds an existing link in discord.py async?

Here is what I have so far:

import discord
import random
import string

def getRandom():
    letters_and_digits = string.ascii_letters + string.digits
    global linkCode
    linkCode = ''.join((random.choice(letters_and_digits) for i in range(11)))

@client.command()
async def randtube(ctx):
    getRandom()
    await ctx.send(f"https://www.youtube.com/watch?v={linkCode}")



Aucun commentaire:

Enregistrer un commentaire