python - 帕菲属性错误
问题描述
我想做一个音乐不和谐机器人,但是当我尝试用 pafy 获取 youtube 视频时,我遇到了一些错误和异常,我不明白为什么,我只需要 pafy 部分的帮助。
这是我的代码:
import discord
import os
import pafy
import vlc
import nacl
import re
client = discord.Client()
@client.event
async def on_ready():
print('connecter en tant que {0.user}'
.format(client))
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('https://www.youtube.com/'):
print(message.content)
video_ids = re.findall(r"watch\?v=(\S{11})", message.content)
print(video_ids[0])
#url = message.content
video = pafy.new(video_ids[0])
audio = video.getbestaudio()
playurl = audio.url
player = vlc.Instance.media_player_new()
Media = vlc.Instance.media_new(playurl)
Media.get_mrl()
player.set_media(Media)
player.play()
elif message.content.startswith('$join'):
channel = message.author.voice.channel
await channel.connect()
elif message.content.startswith('$bye'):
channel = message.guild.voice_client
await channel.disconnect()
这是错误消息:
` 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 26, in on_message
video = pafy.new(video_ids[0])
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pafy/pafy.py", line 124, in new
return Pafy(url, basic, gdata, size, callback, ydl_opts=ydl_opts)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pafy/backend_internal.py", line 42, in __init__
super(InternPafy, self).__init__(*args, **kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pafy/backend_shared.py", line 97, in __init__
self._fetch_basic()
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pafy/backend_internal.py", line 50, in _fetch_basic
allinfo = get_video_info(self.videoid, self.callback)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pafy/backend_internal.py", line 271, in get_video_info
sts = re.search(r'sts"\s*:\s*(\d+)', embed_webpage).group(1)
AttributeError: 'NoneType' object has no attribute 'group' `
我该如何解决?
解决方案
推荐阅读
- php - PHP 和 HTML 的背景需要在 VS Code 中进行不同的分配
- python - NVSS - CDC 死亡率数据 [vital-mortality github repo]
- python - 通过另一个数据帧中的条件缩短数据帧
- spring-boot - Spring Boot 安全性 - 允许使用过期 JWT 令牌的用户请求
- android - 使用 Jetpack Compose Navigation 导航到另一个 Composable 后记住 List State 的最佳实践
- django - 导航栏未正确显示
- python - Python接受的套接字连接未关闭
- r - R:对矩阵进行排序,使高值沿主对角线并向外变小
- java - Maven 无法使用 gitlab 解决依赖关系
- f# - 专家 f# 脚本编译异常