@bot.command(name="cover")
async def cover(ctx, *, song_name):
try:
m = Mega()
m.login(email, password)
mega_folder_link = "https://mega.nz/folder/koknVbLA#_pVoBiVd5vxE4r1dCeZ1kA"
folder = m.find(song_name)
if folder:
for file_info in folder:
file_name, file_extension = file_info['name'], file_info['ext']
if file_extension.lower() in ['jpg', 'png']:
full_file_name = f"{file_name}.{file_extension}"
m.download_url(file_info)
await ctx.send(f"Cover {full_file_name} found and uploaded.")
return
await ctx.send("No valid cover image found in the folder.")
else:
await ctx.send(f"No folder found with that name. {error}")
except Exception as e:
print(e)
await ctx.send("An error occurred while processing the command. Please try again later.")
It’s mostly likely due to, like if you feed the query Gone Clean, it won’t find anything since the file name matching is Gone_Clean.jpg with the underscore, and the query isn’t. So, you’d have to handle that by replacing spaces with the proper underscores.
@bot.command(name="cover")
async def cover(ctx, *, song_name):
try:
m = Mega()
m.login(email, password)
mega_folder_link = "https://mega.nz/folder/koknVbLA#_pVoBiVd5vxE4r1dCeZ1kA"
song_name = song_name.replace(" ", "_")
files = m.get_files()
if files:
for file_info in files:
if 'name' in file_info and 'ext' in file_info:
file_name, file_extension = file_info['name'], file_info['ext']
if song_name.lower() in file_name.lower() and file_extension.lower() in ['jpg', 'png']:
full_file_name = f"{file_name}.{file_extension}"
m.download_url(file_info)
await ctx.send(f"Cover {full_file_name} found and uploaded.")
return
await ctx.send("No valid cover image found in the folder.")
else:
await ctx.send("No files found in the folder.")
except Exception as e:
print(e)
await ctx.send("An error occurred while processing the command. Please try again later.")