Compare commits
29 Commits
A-0.1
...
fadb42bbf6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fadb42bbf6 | ||
|
|
5fddad561d | ||
|
|
651cf70885 | ||
|
|
02609a65e5 | ||
|
|
837686c71d | ||
|
|
6b8a8a0dfc | ||
|
|
9540f37d06 | ||
|
|
f87f878ca4 | ||
|
|
52cf259c20 | ||
|
|
3893e6ddc0 | ||
|
|
de2779b61f | ||
|
|
6070780b0a | ||
|
|
c2e3081995 | ||
|
|
7e0a927c2b | ||
|
|
ba14c23ed9 | ||
|
|
e770272bc4 | ||
|
|
f6439245c6 | ||
|
|
3496e0e5a7 | ||
|
|
22e74ff829 | ||
|
|
467f2dd00b | ||
|
|
dec4be3d1b | ||
|
|
7a09c752e9 | ||
|
|
93ec9ca2ec | ||
|
|
9f61462777 | ||
|
|
1d5e32eec0 | ||
|
|
b286d8338e | ||
|
|
9735a408c9 | ||
|
|
e9bcaa210c | ||
|
|
ede2a02bb7 |
34
Music-Bot.py
34
Music-Bot.py
@@ -4,6 +4,7 @@ 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
|
||||||
|
|
||||||
@@ -17,6 +18,7 @@ version = "0.1"
|
|||||||
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 +35,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 +78,8 @@ 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)
|
||||||
|
|
||||||
|
|
||||||
intents = discord.Intents.default()
|
intents = discord.Intents.default()
|
||||||
@@ -85,7 +88,7 @@ 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
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -99,12 +102,21 @@ else:
|
|||||||
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
|
||||||
except Exception as err:
|
|
||||||
print(err)
|
|
||||||
if channel is None:
|
if channel is None:
|
||||||
await ctx.send(f"{error}You are not in a voice-channel! Could not join...")
|
await ctx.send(f"{error}You are not in a voice-channel! Could not join...")
|
||||||
if ctx.voice_client is not None:
|
if ctx.voice_client is not None:
|
||||||
@@ -112,6 +124,8 @@ else:
|
|||||||
|
|
||||||
await ctx.respond(f"{success}Connected to `{channel.name}`")
|
await ctx.respond(f"{success}Connected to `{channel.name}`")
|
||||||
await channel.connect()
|
await channel.connect()
|
||||||
|
except Exception as err:
|
||||||
|
print(err)
|
||||||
|
|
||||||
|
|
||||||
@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")
|
||||||
@@ -200,15 +214,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 +235,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
Music-Bot.pyc
BIN
Music-Bot.pyc
Binary file not shown.
@@ -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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user