Reputation: 1
im new with discord.py and I want to create a youtube downloader code but this doesnt work Here is my code:
@bot.event
async def on_message(message):
if message.author == bot.user:
return
if message.content.startswith('-a'):
msg = message.content
print(f'Mesagge content: {msg} \n')
url = re.findall(r'(?:(?:https?|ftp):\/\/)?[\w/\-?=%.]+\.[\w/\-?=%.]+', msg)
print(url)
if url:
if (len(url) == 1):
validated_yt_url_1 = 'https://www.youtube.com/watch?v='
validated_yt_url_2 = 'https://youtu.be/'
if(validated_yt_url_1 in url[0] or validated_yt_url_2 in url[0]):
print('Youtube link is valid...')
mp3.song(url)
os.listdir()
for files in glob.glob('*.mp3'):
file_size = getsize(files)
file_size = int(file_size)
if file_size > 8000000:
print('The file size is over 8MB...\n')
embedVar = discord.Embed(title="Something went wrong :confused:\n\nTry sending a song that is under 7 minutes long, \nbecause of Discord's file size limit.\\Check out -help and -info commands.", color=0x0066ff)
await message.channel.send(embed=embedVar)
os.remove(files)
print('File was removed')
else:
await message.channel.send(file=discord.File(files))
print('File was sent...\n')
os.remove(files)
print('File was deleted...\n')
else:
await message.channel.send(embed=embedVar)
print('The link was not valid')
else:
embedVar = discord.Embed(title="Something went wrong :confused: \n\nIt looks like you sent more than one url's, please send one url at time.\n\nCheck out -help and -info commands.", color=0x0066ff)
await message.channel.send(embed=embedVar)
And the error is:
Mesagge content: -a https://www.youtube.com/watch?v=-LkmFwYvyd8
['https://www.youtube.com/watch?v=-LkmFwYvyd8']
Youtube link is valid...
Ignoring exception in on_message
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "main.py", line 656, in on_message
mp3.song(url)
AttributeError: module 'mp3' has no attribute 'song'
If somebody helps me i will apreciate it, should also be noted that I have other events such as on_message_edit
Upvotes: 0
Views: 41
Reputation: 3649
As the error message states, the module mp3
has been imported but doesn't contain a function named song
. I'll assume it's from a package you installed. Either it doesn't contain song
and you need to read the documentation for that module to find out how to use it correctly, or you have your own file named mp3.py that is being imported instead of the module you expected.
Upvotes: 1