44 Commits
Author SHA1 Message Date
Lukas Blacha be24384610 Added Youtube Search-Command 2023-02-08 13:14:23 +01:00
Lukas Blacha e1f1fedfdf Added youtube_search method 2023-02-08 12:54:36 +01:00
Lukas Blacha 4aabde261b Added youtube_search method 2023-02-08 12:48:01 +01:00
Lukas Blacha 53f175379f Added youtube_search method 2023-02-08 12:47:08 +01:00
Lukas Blacha 6993fde7d8 Changed Google-Search to Youtube (fix) 2023-02-08 12:42:49 +01:00
Lukas Blacha bc8b212504 Changed Google-Search to Youtube (fix) 2023-02-08 12:42:14 +01:00
Lukas Blacha e51f75c57c Changed Google-Search to Youtube (fix) 2023-02-08 12:39:56 +01:00
Lukas Blacha 08934559b8 Changed Google-Search to Youtube (fix) 2023-02-08 12:16:41 +01:00
Lukas Blacha 93fdfb1f77 Changed Google-Search to Youtube (fix) 2023-02-08 12:15:27 +01:00
Lukas Blacha 9b1e473ec1 Changed Google-Search to Youtube (fix) 2023-02-08 12:15:03 +01:00
Lukas Blacha 7ffc356b1c Changed Google-Search to Youtube (fix) 2023-02-08 12:14:00 +01:00
Lukas Blacha 71bd1f6ae5 Changed Google-Search to Youtube (fix) 2023-02-08 12:11:04 +01:00
Lukas Blacha 5d58d05668 Changed Google-Search to Youtube 2023-02-08 12:10:18 +01:00
Lukas Blacha c1e731aa4d Added branch variable 2023-02-08 11:45:52 +01:00
Lukas Blacha c08bad409f Added Google-Command 2023-02-08 11:42:24 +01:00
Lukas Blacha fadb42bbf6 Removed help-Command 2023-02-07 23:18:57 +01:00
Lukas Blacha 5fddad561d Removed help-Command 2023-02-07 23:16:02 +01:00
Lukas Blacha 651cf70885 Removed help-Command 2023-02-07 23:14:07 +01:00
Lukas Blacha 02609a65e5 Added Shutdown-Command with cleanup 2023-02-07 23:12:03 +01:00
Lukas Blacha 837686c71d Added Shutdown-Command with cleanup 2023-02-07 23:10:05 +01:00
Lukas Blacha 6b8a8a0dfc Added Shutdown-Command with cleanup 2023-02-07 23:05:31 +01:00
Lukas Blacha 9540f37d06 Added Shutdown-Command 2023-02-07 23:02:51 +01:00
Lukas Blacha f87f878ca4 Added threads flag 2023-02-07 22:58:10 +01:00
Gitea 52cf259c20 Made the bot working again... 2023-02-07 21:55:41 +00:00
Gitea 3893e6ddc0 Removed maxrate flag 2023-02-07 21:48:25 +00:00
Gitea de2779b61f Removed OPUS decoder 2023-02-07 21:47:20 +00:00
Lukas Blacha 6070780b0a Added threads flag 2023-02-07 22:45:19 +01:00
Lukas Blacha c2e3081995 Added threads flag 2023-02-07 22:42:04 +01:00
Lukas Blacha 7e0a927c2b Added threads flag 2023-02-07 22:35:48 +01:00
Lukas Blacha ba14c23ed9 Switched back to ffmepgPCM 2023-02-07 22:32:28 +01:00
Lukas Blacha e770272bc4 Switched back to ffmepgPCM 2023-02-07 22:31:08 +01:00
Lukas Blacha f6439245c6 Switched back to ffmepgPCM 2023-02-07 22:27:45 +01:00
Lukas Blacha 3496e0e5a7 Switched to OpusVoice 2023-02-07 22:24:06 +01:00
Lukas Blacha 22e74ff829 Switched to OpusVoice 2023-02-07 22:23:01 +01:00
Lukas Blacha 467f2dd00b Switched to OpusVoice 2023-02-07 22:21:01 +01:00
Lukas Blacha dec4be3d1b Switched to OpusVoice 2023-02-07 22:14:00 +01:00
Lukas Blacha 7a09c752e9 Switched to OpusVoice 2023-02-07 22:09:38 +01:00
Lukas Blacha 93ec9ca2ec Switched to OpusVoice 2023-02-07 22:08:20 +01:00
Lukas Blacha 9f61462777 Switched to OpusVoice 2023-02-07 22:07:41 +01:00
Lukas Blacha 1d5e32eec0 Switched to OpusVoice 2023-02-07 22:04:51 +01:00
Lukas Blacha b286d8338e Switched to OpusVoice 2023-02-07 22:01:19 +01:00
Lukas Blacha 9735a408c9 Added bot=True, reconnect=True 2023-02-07 21:37:27 +01:00
Lukas e9bcaa210c Deleted compiled version 2023-02-07 15:42:23 +00:00
Lukas Blacha ede2a02bb7 Fixes 2023-02-07 16:38:48 +01:00
3 changed files with 65 additions and 17 deletions

No files matched your search

+64 -16
View File
@@ -1,9 +1,14 @@
import asyncio import asyncio
import re
from datetime import timedelta from datetime import timedelta
from urllib.parse import quote_plus
import aiohttp
import yt_dlp import yt_dlp
import discord import discord
import logging import logging
import argparse import argparse
import os
from discord.ext import commands from discord.ext import commands
from discord import Embed from discord import Embed
@@ -14,9 +19,11 @@ banner = """
_| _| \__,_| ____/ _| \___| ____/ \___/ \__| _| _| \__,_| ____/ _| \___| ____/ \___/ \__|
""" """
version = "0.1" version = "0.1"
branch = "dev"
success = "**Success ✅**\n" success = "**Success ✅**\n"
warning = "**Warning ℹ️**\n" warning = "**Warning ℹ️**\n"
error = "**Error ❗️**\n" error = "**Error ❗️**\n"
cache_dir = "cache"
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("-t", "--token", help="Bot TOKEN") parser.add_argument("-t", "--token", help="Bot TOKEN")
@@ -33,7 +40,7 @@ else:
ytdl_format_options = { ytdl_format_options = {
"format": "bestaudio/mp3", "format": "bestaudio/mp3",
"outtmpl": "cache/%(extractor)s-%(id)s-%(title)s.mp3", "outtmpl": f"{cache_dir}/%(extractor)s-%(id)s-%(title)s.mp3",
"restrictfilenames": True, "restrictfilenames": True,
"noplaylist": True, "noplaylist": True,
"nocheckcertificate": True, "nocheckcertificate": True,
@@ -76,7 +83,20 @@ else:
data = data["entries"][0] data = data["entries"][0]
filename = data["url"] if stream else ytdl.prepare_filename(data) filename = data["url"] if stream else ytdl.prepare_filename(data)
return cls(discord.FFmpegPCMAudio(filename, **ffmpeg_options), data=data) return cls(discord.FFmpegPCMAudio(source=filename, executable="ffmpeg", pipe=False, stderr=False,
before_options="-threads 2", options=ffmpeg_options), data=data)
async def youtube_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://www.youtube.com/results", params=p, headers=h) as resp:
dom = await resp.text()
found = re.findall(r"watch\?v=(\S{11})", dom)[0]
url = f"https://www.youtube.com/watch?v={found}"
return url
intents = discord.Intents.default() intents = discord.Intents.default()
@@ -85,33 +105,44 @@ else:
bot = commands.Bot( bot = commands.Bot(
command_prefix=commands.when_mentioned_or("!"), command_prefix=commands.when_mentioned_or("!"),
description="Relatively simple music bot example", description="Relatively simple music bot example",
intents=intents, intents=intents, help_command=None
) )
@bot.event @bot.event
async def on_ready(): async def on_ready():
print(banner) print(banner)
print(f"Bot Version: {version}") print(f"Bot Version: {version} ({branch})")
print(f"Bot: {bot.user} (ID: {bot.user.id})") print(f"Bot: {bot.user} (ID: {bot.user.id})")
print( print(
f"Invitation LINK: https://discord.com/api/oauth2/authorize?client_id={bot.user.id}&permissions=968552344896&scope=bot%20applications.commands") f"Invitation LINK: https://discord.com/api/oauth2/authorize?client_id={bot.user.id}&permissions=968552344896&scope=bot%20applications.commands")
print("------") print("------")
@bot.command(name="shutdown")
@commands.is_owner()
async def _shutdown(ctx):
files = os.listdir(cache_dir)
async with ctx.channel.typing():
for file in files:
os.remove(f"{cache_dir}/{file}")
await ctx.send(f"{warning}Cleaned up {len(files)} Files...\n\n{success}Shutting down...")
await bot.close()
@bot.slash_command(name="join", description="Summon the bot into your channel") @bot.slash_command(name="join", description="Summon the bot into your channel")
async def join(ctx: commands.Context): async def join(ctx: commands.Context):
try: try:
channel = ctx.author.voice.channel channel = ctx.author.voice.channel
if channel is None:
await ctx.send(f"{error}You are not in a voice-channel! Could not join...")
if ctx.voice_client is not None:
return await ctx.voice_client.move_to(channel)
await ctx.respond(f"{success}Connected to `{channel.name}`")
await channel.connect()
except Exception as err: except Exception as err:
print(err) print(err)
if channel is None:
await ctx.send(f"{error}You are not in a voice-channel! Could not join...")
if ctx.voice_client is not None:
return await ctx.voice_client.move_to(channel)
await ctx.respond(f"{success}Connected to `{channel.name}`")
await channel.connect()
@bot.slash_command(name="nowplaying", descriprion="Show details what the bot is currently playing") @bot.slash_command(name="nowplaying", descriprion="Show details what the bot is currently playing")
@@ -184,8 +215,25 @@ else:
await ctx.voice_client.disconnect(force=True) await ctx.voice_client.disconnect(force=True)
@bot.slash_command(name="youtube", description="Searches YouTube for a given string and plays the first result")
async def youtube(ctx, *, search: str):
url = await youtube_search(search=search)
async with ctx.typing():
await ctx.respond("🤖 Your song is queued for download... please wait ", ephemeral=True)
try:
player = await YTDLSource.from_url(url, loop=bot.loop)
ctx.voice_client.play(
player, after=lambda e: print(f"Player error: {e}") if e else None
)
except discord.HTTPException as err:
raise commands.CommandError(err)
finally:
await ctx.send(f"{success}Now playing: `{player.title}`\nRequested by {ctx.author.mention}")
@play.before_invoke @play.before_invoke
@stream.before_invoke @stream.before_invoke
@youtube.before_invoke
async def ensure_voice(ctx: commands.Context): async def ensure_voice(ctx: commands.Context):
if ctx.voice_client is None: if ctx.voice_client is None:
if ctx.author.voice: if ctx.author.voice:
@@ -200,15 +248,16 @@ else:
async def on_application_command_error(ctx, error): async def on_application_command_error(ctx, error):
print(f"[on_application_command_error]\n{ctx.author}\n{error}") print(f"[on_application_command_error]\n{ctx.author}\n{error}")
if isinstance(error, discord.ext.commands.CommandError): if isinstance(error, discord.ext.commands.CommandError):
cool_down_time = int(error.cooldown.get_retry_after()) embed = Embed(title=f"{warning}{error}",
td = timedelta(seconds=cool_down_time)
embed = Embed(title=f"{warning}Dieser Command befindet sich im Cool Down!\n Versuche es in `{td}` nochmal!",
color=15158332) color=15158332)
elif isinstance(error, discord.ext.commands.CommandOnCooldown): elif isinstance(error, discord.ext.commands.CommandOnCooldown):
cool_down_time = int(error.cooldown.get_retry_after()) cool_down_time = int(error.cooldown.get_retry_after())
td = timedelta(seconds=cool_down_time) td = timedelta(seconds=cool_down_time)
embed = Embed(title=f"{warning}Dieser Command befindet sich im Cool Down!\n Versuche es in `{td}` nochmal!", embed = Embed(title=f"{warning}Dieser Command befindet sich im Cool Down!\n Versuche es in `{td}` nochmal!",
color=15158332) color=15158332)
elif isinstance(error, discord.ext.commands.is_owner()):
embed = Embed(title=f"{warning}{error}",
color=15158332)
else: else:
embed = Embed(title=f"{error}", color=15158332) embed = Embed(title=f"{error}", color=15158332)
await ctx.respond(embed=embed) await ctx.respond(embed=embed)
@@ -220,5 +269,4 @@ else:
embed = Embed(title=f"{error}", color=15158332) embed = Embed(title=f"{error}", color=15158332)
await ctx.send(embed=embed) await ctx.send(embed=embed)
bot.run(token=args.token, reconnect=True)
bot.run(args.token)
BIN
View File
Binary file not shown.
+1 -1
View File
@@ -10,7 +10,7 @@ Simple Music-Bot for Discord written in Python with <3
## How to start ## How to start
1. Clone the repository 1. Clone the repository
2. cd into it 2. cd into it
3. Run the **compiled** version: python3 Music-Bot.pyc -t TOKEN 3. Run : python3 Music-Bot.pyc -t TOKEN
4. Click on the invitation-Link in the terminal 4. Click on the invitation-Link in the terminal
5. DONE <3 5. DONE <3