Compare commits
1 Commits
A-0.3
...
a3c818a963
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a3c818a963 |
44
Music-Bot.py
44
Music-Bot.py
@@ -1,7 +1,6 @@
|
||||
import asyncio
|
||||
import re
|
||||
from datetime import timedelta
|
||||
from urllib.parse import quote_plus
|
||||
|
||||
import aiohttp
|
||||
import yt_dlp
|
||||
@@ -18,9 +17,8 @@ banner = """
|
||||
| | | | \__ \ | ( _____| | | ( | |
|
||||
_| _| \__,_| ____/ _| \___| ____/ \___/ \__|
|
||||
"""
|
||||
|
||||
version = "0.1"
|
||||
branch = "dev"
|
||||
version = "0.2"
|
||||
branch = "main"
|
||||
success = "**Success ✅**\n"
|
||||
warning = "**Warning ℹ️**\n"
|
||||
error = "**Error ❗️**\n"
|
||||
@@ -28,24 +26,9 @@ cache_dir = "cache"
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-t", "--token", help="Bot TOKEN")
|
||||
parser.add_argument("-c", "--cores", help="Number of Cores for ffmpeg (Standard 2)")
|
||||
parser.add_argument("-p", "--prefix", help="Provides the Prefix for the bot (Standard <)")
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
if args.cores == None:
|
||||
threads = 2
|
||||
else:
|
||||
threads = int(args.cores)
|
||||
|
||||
|
||||
if args.prefix == None:
|
||||
b_prefix = "<"
|
||||
else:
|
||||
b_prefix = str(args.prefix)
|
||||
|
||||
|
||||
if args.token is None:
|
||||
if args.token == None:
|
||||
print(f"{banner}\n\nPLEASE PROVIDE BOT A TOKEN BY RUNNING LIKE THE FOLLOWING:")
|
||||
print("\n")
|
||||
print(">>> python3 Music-Bot.py -t TOKEN <<<")
|
||||
@@ -100,7 +83,7 @@ else:
|
||||
|
||||
filename = data["url"] if stream else ytdl.prepare_filename(data)
|
||||
return cls(discord.FFmpegPCMAudio(source=filename, executable="ffmpeg", pipe=False, stderr=False,
|
||||
before_options=f"-threads {threads}", options=ffmpeg_options), data=data)
|
||||
before_options="-threads 2", options=ffmpeg_options), data=data)
|
||||
|
||||
|
||||
async def youtube_search(search: str):
|
||||
@@ -119,7 +102,7 @@ else:
|
||||
intents.message_content = True
|
||||
|
||||
bot = commands.Bot(
|
||||
command_prefix=commands.when_mentioned_or(b_prefix),
|
||||
command_prefix=commands.when_mentioned_or("!"),
|
||||
description="Relatively simple music bot example",
|
||||
intents=intents, help_command=None
|
||||
)
|
||||
@@ -130,8 +113,6 @@ else:
|
||||
print(banner)
|
||||
print(f"Bot Version: {version} ({branch})")
|
||||
print(f"Bot: {bot.user} (ID: {bot.user.id})")
|
||||
print(f"Threads for ffmpeg: {threads}")
|
||||
print(f"Prefix: {b_prefix}")
|
||||
print(
|
||||
f"Invitation LINK: https://discord.com/api/oauth2/authorize?client_id={bot.user.id}&permissions=968552344896&scope=bot%20applications.commands")
|
||||
print("------")
|
||||
@@ -194,10 +175,6 @@ else:
|
||||
raise commands.CommandError(err)
|
||||
finally:
|
||||
await ctx.send(f"{success}Now playing: `{player.title}`\nRequested by {ctx.author.mention}")
|
||||
while ctx.voice_client.is_playing():
|
||||
await asyncio.sleep(3)
|
||||
else:
|
||||
await ctx.voice_client.disconnect()
|
||||
|
||||
|
||||
@bot.slash_command(name="stream", description="Streams a song from YouTube [Without preloading]")
|
||||
@@ -207,11 +184,8 @@ else:
|
||||
ctx.voice_client.play(
|
||||
player, after=lambda e: print(f"Player error: {e}") if e else None
|
||||
)
|
||||
|
||||
await ctx.respond(f"{success}Now playing: `{player.title}`\nRequested by {ctx.author.mention}")
|
||||
while ctx.voice_client.is_playing():
|
||||
await asyncio.sleep(3)
|
||||
else:
|
||||
await ctx.voice_client.disconnect()
|
||||
|
||||
|
||||
@bot.slash_command(name="pause", description="Pauses the playback")
|
||||
@@ -254,10 +228,6 @@ else:
|
||||
raise commands.CommandError(err)
|
||||
finally:
|
||||
await ctx.send(f"{success}Now playing: `{player.title}`\nRequested by {ctx.author.mention}")
|
||||
while ctx.voice_client.is_playing():
|
||||
await asyncio.sleep(3)
|
||||
else:
|
||||
await ctx.voice_client.disconnect()
|
||||
|
||||
|
||||
@play.before_invoke
|
||||
@@ -273,8 +243,6 @@ else:
|
||||
ctx.voice_client.stop()
|
||||
|
||||
|
||||
|
||||
|
||||
@bot.event
|
||||
async def on_application_command_error(ctx, error):
|
||||
print(f"[on_application_command_error]\n{ctx.author}\n{error}")
|
||||
|
||||
Reference in New Issue
Block a user