質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Discord

Discordは、ゲーマー向けのボイスチャットアプリです。チャット・通話がブラウザ上で利用可能で、個人専用サーバーも開設できます。通話中でも音楽を流したり、PC画面を共有できるなど多機能な点が特徴です。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Q&A

解決済

1回答

1007閲覧

python3でURLError('unknown url type: tps')の対処法

ki-ma

総合スコア14

Discord

Discordは、ゲーマー向けのボイスチャットアプリです。チャット・通話がブラウザ上で利用可能で、個人専用サーバーも開設できます。通話中でも音楽を流したり、PC画面を共有できるなど多機能な点が特徴です。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

0グッド

0クリップ

投稿2022/05/29 06:52

編集2022/05/29 07:46

python3でdiscord.pyで(youtubeの音楽が聴ける)botを作ろうとしたのですが謎のURLERRORが出てしまいます。
対処法を教えていただけませんでしょうか。

python<**codo**>

1import asyncio 2 3import discord 4import youtube_dl 5 6TOKEN = "" 7youtube_dl.utils.bug_reports_message = lambda: '' 8 9ytdl_format_options = { 10 'format': 'bestaudio/best', 11 'outtmpl': '%(extractor)s-%(id)s-%(title)s.%(ext)s', 12 'restrictfilenames': True, 13 'noplaylist': True, 14 'nocheckcertificate': True, 15 'ignoreerrors': False, 16 'logtostderr': False, 17 'quiet': True, 18 'no_warnings': True, 19 'default_search': 'auto', 20 'source_address': '0.0.0.0' # bind to ipv4 since ipv6 addresses cause issues sometimes 21} 22 23ffmpeg_options = { 24 'options': '-vn' 25} 26 27ytdl = youtube_dl.YoutubeDL(ytdl_format_options) 28 29 30class YTDLSource(discord.PCMVolumeTransformer): 31 def __init__(self, source, *, data, volume=0.5): 32 super().__init__(source, volume) 33 34 self.data = data 35 36 self.title = data.get('title') 37 self.url = data.get("url") 38 39 @classmethod 40 async def from_url(cls, url, *, loop=None, stream=False): 41 loop = loop or asyncio.get_event_loop() 42 data = await loop.run_in_executor(None, lambda: ytdl.extract_info(url, download=not stream)) 43 44 if 'entries' in data: 45 # take first item from a playlist 46 data = data['entries'][0] 47 48 filename = data['url'] if stream else ytdl.prepare_filename(data) 49 return cls(discord.FFmpegPCMAudio(filename, **ffmpeg_options), data=data) 50 51 52client = discord.Client() 53 54@client.event 55async def on_ready(): 56 print('Login!!!') 57 58 59 60@client.event 61async def on_message(message: discord.Message): 62 # メッセージの送信者がbotだった場合は無視する 63 if message.author.bot: 64 return 65 66 if message.content == "!join": 67 if message.author.voice is None: 68 await message.channel.send("あなたはボイスチャンネルに接続していません。") 69 return 70 # ボイスチャンネルに接続する 71 await message.author.voice.channel.connect() 72 await message.channel.send("接続しました。") 73 74 elif message.content == "!leave": 75 if message.guild.voice_client is None: 76 await message.channel.send("接続していません。") 77 return 78 79 # 切断する 80 await message.guild.voice_client.disconnect() 81 82 await message.channel.send("切断しました。") 83 84 85 elif message.content.startswith("!dl "): 86 if message.guild.voice_client is None: 87 await message.channel.send("接続していません。") 88 return 89 # 再生中の場合は再生しない 90 if message.guild.voice_client.is_playing(): 91 await message.channel.send("再生中です。") 92 return 93 94 url = message.content[6:] 95 print(url) 96 # youtubeから音楽をダウンロードする 97 player = await YTDLSource.from_url(url, loop=client.loop) 98 99 await message.channel.send('{} のダウンロードが完了しました。。'.format(player.title)) 100 101 102 elif message.content.startswith("!play "): 103 if message.guild.voice_client is None: 104 await message.channel.send("接続していません。") 105 return 106 # 再生中の場合は再生しない 107 if message.guild.voice_client.is_playing(): 108 await message.channel.send("再生中です。") 109 return 110 111 url = message.content[6:] 112 print(url) 113 # youtubeから音楽をダウンロードする 114 player = await YTDLSource.from_url(url, loop=client.loop) 115 116 117 # 再生する 118 message.guild.voice_client.play(player) 119 120 await message.channel.send('{} を再生します。'.format(player.title)) 121 122 123 124 125 126 127 elif message.content == "!stop": 128 if message.guild.voice_client is None: 129 await message.channel.send("接続していません。") 130 return 131 132 # 再生中ではない場合は実行しない 133 if not message.guild.voice_client.is_playing(): 134 await message.channel.send("再生していません。") 135 return 136 137 message.guild.voice_client.stop() 138 139 await message.channel.send("ストップしました。") 140client.run(TOKEN)

ERROR

1DownloadError(message, exc_info) 2youtube_dl.utils.DownloadError: ERROR: Unable to download 3webpage: <urlopen error unknown url type: tps> (caused by 4URLError('unknown url type: tps'))

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

長い上に、どの行でのエラーかもわからないのでコードは読んでませんが、
URLの先頭2文字が欠けてしまったと言うことでしょう。"tps://example.com"のようなURLを参照しようとするとそういうエラーメッセージになります。

目で処理を追ってもわからないのなら、どの時点まで正しいURLだったのか調べるためにprintを入れるなりして調べましょう。

投稿2022/05/29 09:28

otn

総合スコア84531

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

ki-ma

2022/05/30 04:38

返信ありがとうございます! printを入れて確認してみたところURLの戦闘が欠けていました。 url = message.content[4:] ここの数字を6から4に変更してみたところURLが欠けずに正常によみこめました! ありがとうございました! ベストアンサーにさせていただきます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問