mirror of
https://github.com/G2-Games/simple-discord-music-bot.git
synced 2025-04-19 16:02:54 -05:00
Fixed many small issues
This commit is contained in:
parent
5dca7c5726
commit
6ec5d6355b
3 changed files with 20 additions and 14 deletions
|
@ -1,5 +1,5 @@
|
||||||
discord==2.3
|
discord==2.3
|
||||||
ffmpeg-python==0.2
|
ffmpeg-python==0.2
|
||||||
stringprogressbar==1.1
|
stringprogressbar==1.1.1
|
||||||
pynacl==1.5
|
pynacl==1.5
|
||||||
yt-dlp==2024.8.6
|
yt-dlp==2024.8.6
|
||||||
|
|
31
src/main.py
31
src/main.py
|
@ -88,14 +88,14 @@ async def play(ctx, *, query: str = None):
|
||||||
if ctx.message.attachments:
|
if ctx.message.attachments:
|
||||||
success_list = []
|
success_list = []
|
||||||
notice = await ctx.send(":arrow_double_up: Uploading...", suppress_embeds=True)
|
notice = await ctx.send(":arrow_double_up: Uploading...", suppress_embeds=True)
|
||||||
success_string = ":white_check_mark: Successfully uploaded: \n"
|
success_string = "File Status: \n"
|
||||||
for song in ctx.message.attachments:
|
for song in ctx.message.attachments:
|
||||||
filename, thumbname = utils.getFileNames(server_id)
|
filename, thumbname = utils.getFileNames(server_id)
|
||||||
|
|
||||||
# Make sure the file is either audio or video
|
# Make sure the file is either audio or video
|
||||||
filetype = song.content_type
|
filetype = song.content_type
|
||||||
if filetype is None or (filetype.split('/')[0] != "audio" and filetype.split('/')[0] != "video"):
|
if filetype is None or (filetype.split('/')[0] != "audio" and filetype.split('/')[0] != "video"):
|
||||||
await notice.edit(content=":no_entry_sign: Not a valid video or audio file...")
|
success_string += ":no_entry_sign: — `" + song.filename + "`, invalid file!\n"
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Save the song to the temp folder
|
# Save the song to the temp folder
|
||||||
|
@ -105,10 +105,11 @@ async def play(ctx, *, query: str = None):
|
||||||
item = utils.parseMediaFile(song, filename, thumbname)
|
item = utils.parseMediaFile(song, filename, thumbname)
|
||||||
success_list.append(item["name"]);
|
success_list.append(item["name"]);
|
||||||
|
|
||||||
success_string += " –`" + item["name"] + "`\n"
|
success_string += ":white_check_mark: — `" + item["name"] + "`\n"
|
||||||
|
|
||||||
await notice.edit(content=success_string)
|
await notice.edit(content=success_string)
|
||||||
server_info[server_id]["queue"].append(item)
|
server_info[server_id]["queue"].append(item)
|
||||||
|
print(str(server_id) + " | " + f"Uploaded {song.filename}")
|
||||||
|
|
||||||
if len(success_list) > 0:
|
if len(success_list) > 0:
|
||||||
await notice.edit(content=success_string, delete_after=3)
|
await notice.edit(content=success_string, delete_after=3)
|
||||||
|
@ -261,7 +262,6 @@ async def play(ctx, *, query: str = None):
|
||||||
|
|
||||||
# Create embed
|
# Create embed
|
||||||
embed=discord.Embed(title="▶️ Playing: " + song_name, url=song_url, description=song_desc, color=color)
|
embed=discord.Embed(title="▶️ Playing: " + song_name, url=song_url, description=song_desc, color=color)
|
||||||
|
|
||||||
if song_thumb is not None:
|
if song_thumb is not None:
|
||||||
embed.set_thumbnail(url="attachment://" + song_thumbname)
|
embed.set_thumbnail(url="attachment://" + song_thumbname)
|
||||||
elif song_thumb_url is not None:
|
elif song_thumb_url is not None:
|
||||||
|
@ -274,6 +274,13 @@ async def play(ctx, *, query: str = None):
|
||||||
)
|
)
|
||||||
await playing.edit(embed=embed)
|
await playing.edit(embed=embed)
|
||||||
|
|
||||||
|
embed = discord.Embed(title=":stop_button: Finished Playing: " + song_name, url=song_url, description=song_desc, color=color)
|
||||||
|
if song_thumb is not None:
|
||||||
|
embed.set_thumbnail(url="attachment://" + song_thumbname)
|
||||||
|
elif song_thumb_url is not None:
|
||||||
|
embed.set_thumbnail(url=song_thumb_url)
|
||||||
|
await playing.edit(embed=embed)
|
||||||
|
|
||||||
server_info[server_id]["elapsed"] = 0
|
server_info[server_id]["elapsed"] = 0
|
||||||
if not server_info[server_id]["loop"]:
|
if not server_info[server_id]["loop"]:
|
||||||
# Increment the queue position by 1
|
# Increment the queue position by 1
|
||||||
|
@ -305,7 +312,7 @@ async def play(ctx, *, query: str = None):
|
||||||
|
|
||||||
|
|
||||||
@bot.command()
|
@bot.command()
|
||||||
async def skip(ctx, direction = None, number = None):
|
async def skip(ctx, command = None, number = None):
|
||||||
# Get all the id and channel info
|
# Get all the id and channel info
|
||||||
server_id, voice_channel, user_voice_channel = await utils.getIds(ctx)
|
server_id, voice_channel, user_voice_channel = await utils.getIds(ctx)
|
||||||
|
|
||||||
|
@ -324,11 +331,11 @@ async def skip(ctx, direction = None, number = None):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Check which direction the user asked to skip
|
# Check which direction the user asked to skip
|
||||||
if direction is None or direction == "forward" or direction.isnumeric():
|
if command is None or command == "forward" or command.isnumeric():
|
||||||
try:
|
try:
|
||||||
if direction.isnumeric():
|
if command.isnumeric():
|
||||||
if int(direction) > 0:
|
if int(command) > 0:
|
||||||
server_info[server_id]["queue_position"] += int(direction) - 1
|
server_info[server_id]["queue_position"] += int(command) - 1
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
if number != None and number > 0:
|
if number != None and number > 0:
|
||||||
|
@ -336,7 +343,7 @@ async def skip(ctx, direction = None, number = None):
|
||||||
|
|
||||||
# Stop the audio playback
|
# Stop the audio playback
|
||||||
voice_channel.stop()
|
voice_channel.stop()
|
||||||
elif direction == "back" and not server_info[server_id]["queue_position"] == 0:
|
elif command == "back" and not server_info[server_id]["queue_position"] == 0:
|
||||||
|
|
||||||
# Decrement the queue position
|
# Decrement the queue position
|
||||||
back = 2
|
back = 2
|
||||||
|
@ -349,8 +356,8 @@ 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 command == "to" and number is not None:
|
||||||
server_info[server_id]["queue_position"] = number - 1
|
server_info[server_id]["queue_position"] = number
|
||||||
|
|
||||||
voice_channel.stop()
|
voice_channel.stop()
|
||||||
elif server_info[server_id]["queue_position"] == 0:
|
elif server_info[server_id]["queue_position"] == 0:
|
||||||
|
|
|
@ -70,7 +70,6 @@ def parseMediaFile(discord_file, tmp_filename: str, tmp_thumbname: str):
|
||||||
thumbnail = tmp_thumbname
|
thumbnail = tmp_thumbname
|
||||||
color_thief = ColorThief(thumbnail)
|
color_thief = ColorThief(thumbnail)
|
||||||
color = color_thief.get_color(quality=1)
|
color = color_thief.get_color(quality=1)
|
||||||
print(color)
|
|
||||||
else:
|
else:
|
||||||
thumbnail = "assets/unknown.png"
|
thumbnail = "assets/unknown.png"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue