mirror of
https://github.com/G2-Games/simple-discord-music-bot.git
synced 2025-04-20 00:12:54 -05:00
Compare commits
2 commits
0d1620d0bd
...
deacd42e6e
Author | SHA1 | Date | |
---|---|---|---|
deacd42e6e | |||
7608c80261 |
3 changed files with 29 additions and 20 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
||||||
.env
|
.env
|
||||||
|
__pycache__/
|
||||||
|
|
Binary file not shown.
48
src/main.py
48
src/main.py
|
@ -28,7 +28,11 @@ bot = commands.Bot(command_prefix="!",intents=discord.Intents.all(), shard_count
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
print("Bot is ready!")
|
print("Bot is ready!")
|
||||||
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name="ななひら"))
|
await bot.change_presence(
|
||||||
|
activity=discord.Activity(
|
||||||
|
type=discord.ActivityType.listening, name="ななひら"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@bot.command()
|
@bot.command()
|
||||||
|
@ -81,9 +85,6 @@ async def play(ctx, *, query: str = None):
|
||||||
await voice_channel.disconnect()
|
await voice_channel.disconnect()
|
||||||
return
|
return
|
||||||
|
|
||||||
if voice_channel.is_playing():
|
|
||||||
await ctx.send("The bot is already playing, adding song to queue", delete_after=3)
|
|
||||||
|
|
||||||
if ctx.message.attachments:
|
if ctx.message.attachments:
|
||||||
downloading = 1
|
downloading = 1
|
||||||
notice = await ctx.send(":arrow_double_up: Uploading...", suppress_embeds=True)
|
notice = await ctx.send(":arrow_double_up: Uploading...", suppress_embeds=True)
|
||||||
|
@ -230,7 +231,7 @@ async def play(ctx, *, query: str = None):
|
||||||
await ctx.send("Something went wrong, please try a different query.", delete_after=3)
|
await ctx.send("Something went wrong, please try a different query.", delete_after=3)
|
||||||
return
|
return
|
||||||
|
|
||||||
print(str(server_id) + " | " + str(item))
|
print(str(server_id) + " | " + str(item["name"]))
|
||||||
|
|
||||||
if voice_channel.is_playing() or downloading == 1:
|
if voice_channel.is_playing() or downloading == 1:
|
||||||
return
|
return
|
||||||
|
@ -276,9 +277,9 @@ async def play(ctx, *, query: str = None):
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
).stdout
|
).stdout
|
||||||
pipe = True
|
pipe = True
|
||||||
print("Playing song through yt-dlp")
|
print(str(server_id) + " | " + "Playing song through yt-dlp")
|
||||||
else:
|
else:
|
||||||
print("Playing song from file")
|
print(str(server_id) + " | " + "Playing song from file")
|
||||||
song_source = song_id
|
song_source = song_id
|
||||||
|
|
||||||
# Play the converted audio in the voice channel from the temporary file
|
# Play the converted audio in the voice channel from the temporary file
|
||||||
|
@ -397,7 +398,7 @@ async def skip(ctx, direction = None, number = None):
|
||||||
# Stop the audio playback of the current track
|
# Stop the audio playback of the current track
|
||||||
voice_channel.stop()
|
voice_channel.stop()
|
||||||
elif direction == "to" and number is not None:
|
elif direction == "to" and number is not None:
|
||||||
server_info[server_id]["queue_position"] = number
|
server_info[server_id]["queue_position"] = number - 1
|
||||||
|
|
||||||
voice_channel.stop()
|
voice_channel.stop()
|
||||||
elif server_info[server_id]["queue_position"] == 0:
|
elif server_info[server_id]["queue_position"] == 0:
|
||||||
|
@ -473,6 +474,7 @@ async def q(ctx, action = None, selection = None):
|
||||||
qu = ""
|
qu = ""
|
||||||
d = ""
|
d = ""
|
||||||
p = ""
|
p = ""
|
||||||
|
total_duration = 0
|
||||||
now_playing = "⠀"
|
now_playing = "⠀"
|
||||||
for entry in server_info[server_id]["queue"]:
|
for entry in server_info[server_id]["queue"]:
|
||||||
if index == server_info[server_id]["queue_position"]:
|
if index == server_info[server_id]["queue_position"]:
|
||||||
|
@ -488,18 +490,22 @@ async def q(ctx, action = None, selection = None):
|
||||||
|
|
||||||
p += now_playing + "\n"
|
p += now_playing + "\n"
|
||||||
qu += "**" + str(index + 1) + ":** " + entry_cut + "\n"
|
qu += "**" + str(index + 1) + ":** " + entry_cut + "\n"
|
||||||
if str(strftime("%H", gmtime(int(float(entry['duration'])))))[0:1] == "00":
|
if int(entry['duration']) < 3600:
|
||||||
d += str(strftime("%M:%S", gmtime(int(float(entry['duration']))))) + "\n"
|
d += str(strftime("%M:%S", gmtime(int(float(entry['duration']))))) + "\n"
|
||||||
else:
|
else:
|
||||||
d += str(strftime("%H:%M:%S", gmtime(int(float(entry['duration']))))) + "\n"
|
d += str(strftime("%H:%M:%S", gmtime(int(float(entry['duration']))))) + "\n"
|
||||||
|
|
||||||
|
if index >= server_info[server_id]["queue_position"]:
|
||||||
|
total_duration += entry['duration']
|
||||||
index += 1
|
index += 1
|
||||||
|
|
||||||
embed = discord.Embed(title="Queue:", description="", color=0xa032a8)
|
total_duration = str(strftime("%H:%M:%S", gmtime(int(float(total_duration)))))
|
||||||
|
|
||||||
|
embed = discord.Embed(title=f"Queue ({total_duration} left):", description="", color=0xa032a8)
|
||||||
try:
|
try:
|
||||||
embed.add_field(name="⠀", value=p, inline=True)
|
embed.add_field(name="⠀", value=p, inline=True)
|
||||||
embed.add_field(name="List", value=qu, inline=True)
|
embed.add_field(name="List", value=qu, inline=True)
|
||||||
embed.add_field(name="Length", value=d, inline=True)
|
embed.add_field(name=f"Length", value=d, inline=True)
|
||||||
except:
|
except:
|
||||||
embed.add_field(name="List", value="Queue is **empty**", inline=False)
|
embed.add_field(name="List", value="Queue is **empty**", inline=False)
|
||||||
|
|
||||||
|
@ -514,13 +520,13 @@ async def q(ctx, action = None, selection = None):
|
||||||
await queue_embed.edit(embed=embed)
|
await queue_embed.edit(embed=embed)
|
||||||
return
|
return
|
||||||
|
|
||||||
if action == "remove":
|
if action == "remove" and selection is not None:
|
||||||
print(str(server_id) + " | " + "Removing item #" + str(selection) + " from queue")
|
print(str(server_id) + " | " + "Removing item #" + str(selection) + " from queue")
|
||||||
selection = selection - 1
|
selection = int(selection) - 1
|
||||||
selection = int(selection)
|
current_position = server_info[server_id]["queue_position"]
|
||||||
position = server_info[server_id]["queue_position"]
|
|
||||||
id = server_info[server_id]["queue"][selection]['id']
|
path = server_info[server_id]["queue"][selection]["id"]
|
||||||
if server_info[server_id]["queue"][selection]['thumbnail'] != "/assets/unknown.png":
|
if server_info[server_id]["queue"][selection]["thumbnail"] != "/assets/unknown.png":
|
||||||
thumbnail = None
|
thumbnail = None
|
||||||
else:
|
else:
|
||||||
thumbnail = server_info[server_id]["queue"][selection]['thumbnail']
|
thumbnail = server_info[server_id]["queue"][selection]['thumbnail']
|
||||||
|
@ -529,10 +535,10 @@ async def q(ctx, action = None, selection = None):
|
||||||
await ctx.send(":no_entry_sign: Error, cannot remove currently playing item", delete_after=3)
|
await ctx.send(":no_entry_sign: Error, cannot remove currently playing item", delete_after=3)
|
||||||
return
|
return
|
||||||
|
|
||||||
if selection != 0 and not int(selection) > len(server_info[server_id]["queue"]):
|
if selection < 0 and not int(selection) > len(server_info[server_id]["queue"]):
|
||||||
try:
|
try:
|
||||||
os.remove(id)
|
os.remove(path)
|
||||||
if not thumbnail is None:
|
if thumbnail is not None:
|
||||||
os.remove(thumbnail)
|
os.remove(thumbnail)
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
@ -550,6 +556,8 @@ async def q(ctx, action = None, selection = None):
|
||||||
await ctx.send(":white_check_mark: Removed item #" + str(selection) + " from queue.", delete_after=3)
|
await ctx.send(":white_check_mark: Removed item #" + str(selection) + " from queue.", delete_after=3)
|
||||||
server_info[server_id]["queue"].pop(selection)
|
server_info[server_id]["queue"].pop(selection)
|
||||||
await q(ctx)
|
await q(ctx)
|
||||||
|
elif action == "remove" and selection is None:
|
||||||
|
await ctx.send(":no_entry_sign: Error, please select a queue item to remove", delete_after=3)
|
||||||
else:
|
else:
|
||||||
await ctx.send(":no_entry_sign: Error, item #" + str(selection) + "not a valid queue item", delete_after=3)
|
await ctx.send(":no_entry_sign: Error, item #" + str(selection) + "not a valid queue item", delete_after=3)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue