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
linkCode = h81
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}")
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…