Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c3eb9a9d73 | ||
|
|
67cb769111 | ||
|
|
cde8430d53 | ||
|
|
07ca78e1bc | ||
|
|
fb0a12c213 | ||
|
|
daaa120594 | ||
|
|
f09d8e3e9c | ||
|
|
0f16af383b | ||
|
|
607752fd4f | ||
|
|
b2d843324d | ||
|
|
7ce9e51155 | ||
|
|
8ff36532cc | ||
|
|
26a2d07714 | ||
|
|
4a0c0161bd | ||
|
|
a16a1e3ad2 | ||
|
|
a194d4a4ef | ||
|
|
f9e5ade444 | ||
|
|
40671616f3 | ||
|
|
116e7e6d15 | ||
|
|
443eec8320 | ||
|
|
71e76d754d |
39
Music-Bot.py
39
Music-Bot.py
@@ -18,6 +18,7 @@ banner = """
|
|||||||
| | | | \__ \ | ( _____| | | ( | |
|
| | | | \__ \ | ( _____| | | ( | |
|
||||||
_| _| \__,_| ____/ _| \___| ____/ \___/ \__|
|
_| _| \__,_| ____/ _| \___| ____/ \___/ \__|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
version = "0.1"
|
version = "0.1"
|
||||||
branch = "dev"
|
branch = "dev"
|
||||||
success = "**Success ✅**\n"
|
success = "**Success ✅**\n"
|
||||||
@@ -27,9 +28,24 @@ 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")
|
||||||
|
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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.token == None:
|
|
||||||
|
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:
|
||||||
print(f"{banner}\n\nPLEASE PROVIDE BOT A TOKEN BY RUNNING LIKE THE FOLLOWING:")
|
print(f"{banner}\n\nPLEASE PROVIDE BOT A TOKEN BY RUNNING LIKE THE FOLLOWING:")
|
||||||
print("\n")
|
print("\n")
|
||||||
print(">>> python3 Music-Bot.py -t TOKEN <<<")
|
print(">>> python3 Music-Bot.py -t TOKEN <<<")
|
||||||
@@ -84,7 +100,7 @@ else:
|
|||||||
|
|
||||||
filename = data["url"] if stream else ytdl.prepare_filename(data)
|
filename = data["url"] if stream else ytdl.prepare_filename(data)
|
||||||
return cls(discord.FFmpegPCMAudio(source=filename, executable="ffmpeg", pipe=False, stderr=False,
|
return cls(discord.FFmpegPCMAudio(source=filename, executable="ffmpeg", pipe=False, stderr=False,
|
||||||
before_options="-threads 2", options=ffmpeg_options), data=data)
|
before_options=f"-threads {threads}", options=ffmpeg_options), data=data)
|
||||||
|
|
||||||
|
|
||||||
async def youtube_search(search: str):
|
async def youtube_search(search: str):
|
||||||
@@ -103,7 +119,7 @@ else:
|
|||||||
intents.message_content = True
|
intents.message_content = True
|
||||||
|
|
||||||
bot = commands.Bot(
|
bot = commands.Bot(
|
||||||
command_prefix=commands.when_mentioned_or("!"),
|
command_prefix=commands.when_mentioned_or(b_prefix),
|
||||||
description="Relatively simple music bot example",
|
description="Relatively simple music bot example",
|
||||||
intents=intents, help_command=None
|
intents=intents, help_command=None
|
||||||
)
|
)
|
||||||
@@ -114,6 +130,8 @@ else:
|
|||||||
print(banner)
|
print(banner)
|
||||||
print(f"Bot Version: {version} ({branch})")
|
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(f"Threads for ffmpeg: {threads}")
|
||||||
|
print(f"Prefix: {b_prefix}")
|
||||||
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("------")
|
||||||
@@ -176,6 +194,10 @@ else:
|
|||||||
raise commands.CommandError(err)
|
raise commands.CommandError(err)
|
||||||
finally:
|
finally:
|
||||||
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}")
|
||||||
|
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]")
|
@bot.slash_command(name="stream", description="Streams a song from YouTube [Without preloading]")
|
||||||
@@ -185,8 +207,11 @@ else:
|
|||||||
ctx.voice_client.play(
|
ctx.voice_client.play(
|
||||||
player, after=lambda e: print(f"Player error: {e}") if e else None
|
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}")
|
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")
|
@bot.slash_command(name="pause", description="Pauses the playback")
|
||||||
@@ -229,6 +254,10 @@ else:
|
|||||||
raise commands.CommandError(err)
|
raise commands.CommandError(err)
|
||||||
finally:
|
finally:
|
||||||
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}")
|
||||||
|
while ctx.voice_client.is_playing():
|
||||||
|
await asyncio.sleep(3)
|
||||||
|
else:
|
||||||
|
await ctx.voice_client.disconnect()
|
||||||
|
|
||||||
|
|
||||||
@play.before_invoke
|
@play.before_invoke
|
||||||
@@ -244,6 +273,8 @@ else:
|
|||||||
ctx.voice_client.stop()
|
ctx.voice_client.stop()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
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}")
|
||||||
|
|||||||
Reference in New Issue
Block a user