Python 为什么终端给我这个错误,所有的模块都被导入了?
我是discord.py的新手,我想创建一个youtube下载程序代码,但这不起作用 这是我的密码:Python 为什么终端给我这个错误,所有的模块都被导入了?,python,discord.py,Python,Discord.py,我是discord.py的新手,我想创建一个youtube下载程序代码,但这不起作用 这是我的密码: @bot.event async def on_message(message): if message.author == bot.user: return if message.content.startswith('-a'): msg = message.content print(f'Mesagge cont
@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)
错误是:
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'
如果有人帮助我,我将对此表示赞赏,还应注意,我还有其他事件,如on_message_edit,如错误消息所述,模块
mp3
已导入,但不包含名为song
的函数。我假设它来自您安装的软件包。它不包含歌曲,您需要阅读该模块的文档以了解如何正确使用它,或者您有自己的名为mp3.py的文件正在导入,而不是您期望的模块