Compare commits
2 Commits
e1f1fedfdf
...
A-0.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
71e76d754d | ||
|
|
be24384610 |
23
Music-Bot.py
23
Music-Bot.py
@@ -18,6 +18,7 @@ banner = """
|
|||||||
| | | | \__ \ | ( _____| | | ( | |
|
| | | | \__ \ | ( _____| | | ( | |
|
||||||
_| _| \__,_| ____/ _| \___| ____/ \___/ \__|
|
_| _| \__,_| ____/ _| \___| ____/ \___/ \__|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
version = "0.1"
|
version = "0.1"
|
||||||
branch = "dev"
|
branch = "dev"
|
||||||
success = "**Success ✅**\n"
|
success = "**Success ✅**\n"
|
||||||
@@ -94,24 +95,10 @@ else:
|
|||||||
async with aiohttp.ClientSession() as client:
|
async with aiohttp.ClientSession() as client:
|
||||||
async with client.get("https://www.youtube.com/results", params=p, headers=h) as resp:
|
async with client.get("https://www.youtube.com/results", params=p, headers=h) as resp:
|
||||||
dom = await resp.text()
|
dom = await resp.text()
|
||||||
open("yt_debug.html", "w").write(dom)
|
|
||||||
found = re.findall(r"watch\?v=(\S{11})", dom)[0]
|
found = re.findall(r"watch\?v=(\S{11})", dom)[0]
|
||||||
url = f"https://www.youtube.com/watch?v={found}"
|
url = f"https://www.youtube.com/watch?v={found}"
|
||||||
return url
|
return url
|
||||||
|
|
||||||
async def soundcloud_search(search: str):
|
|
||||||
p = {"search_query": search}
|
|
||||||
# Spoof a user agent header or the request will immediately fail
|
|
||||||
h = {"User-Agent": "Mozilla/5.0"}
|
|
||||||
async with aiohttp.ClientSession() as client:
|
|
||||||
async with client.get("https://soundcloud.com/search", params=p, headers=h) as resp:
|
|
||||||
dom = await resp.text()
|
|
||||||
open("sc_debug.html", "w").write(dom)
|
|
||||||
found = re.findall(r"(\S{11})", dom)[0]
|
|
||||||
url = f"https://soundcloud.com/{found}"
|
|
||||||
print(url)
|
|
||||||
return url
|
|
||||||
|
|
||||||
|
|
||||||
intents = discord.Intents.default()
|
intents = discord.Intents.default()
|
||||||
intents.message_content = True
|
intents.message_content = True
|
||||||
@@ -229,7 +216,7 @@ else:
|
|||||||
await ctx.voice_client.disconnect(force=True)
|
await ctx.voice_client.disconnect(force=True)
|
||||||
|
|
||||||
|
|
||||||
@bot.slash_command()
|
@bot.slash_command(name="youtube", description="Searches YouTube for a given string and plays the first result")
|
||||||
async def youtube(ctx, *, search: str):
|
async def youtube(ctx, *, search: str):
|
||||||
url = await youtube_search(search=search)
|
url = await youtube_search(search=search)
|
||||||
async with ctx.typing():
|
async with ctx.typing():
|
||||||
@@ -245,12 +232,6 @@ else:
|
|||||||
await ctx.send(f"{success}Now playing: `{player.title}`\nRequested by {ctx.author.mention}")
|
await ctx.send(f"{success}Now playing: `{player.title}`\nRequested by {ctx.author.mention}")
|
||||||
|
|
||||||
|
|
||||||
@bot.slash_command()
|
|
||||||
async def soundcloud(ctx, *, search: str):
|
|
||||||
url = await soundcloud_search(search=search)
|
|
||||||
await ctx.respond(url)
|
|
||||||
|
|
||||||
|
|
||||||
@play.before_invoke
|
@play.before_invoke
|
||||||
@stream.before_invoke
|
@stream.before_invoke
|
||||||
@youtube.before_invoke
|
@youtube.before_invoke
|
||||||
|
|||||||
Reference in New Issue
Block a user