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

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

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

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

Q&A

0回答

651閲覧

音楽botがVCにすら入らない

amenoame

総合スコア1

Python 3.x

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

0グッド

0クリップ

投稿2021/07/10 10:53

前提・実現したいこと

_p のコマンドを用いて通話に入る→音楽再生の流れですが
通話にすら入ってくれません

該当のソースコード

python

1import discord 2import asyncio 3from discord.ext import commands 4import youtube_dl 5 6 7 8youtube_dl.utils.bug_reports_message = lambda: '' 9 10 11ytdl_format_options = { 12 'format': 'bestaudio/best', 13 'outtmpl': '%(extractor)s-%(id)s-%(title)s.%(ext)s', 14 'restrictfilenames': True, 15 'noplaylist': True, 16 'nocheckcertificate': True, 17 'ignoreerrors': False, 18 'logtostderr': False, 19 'quiet': True, 20 'no_warnings': True, 21 'default_search': 'auto', 22 # bind to ipv4 since ipv6 addresses cause issues sometimes 23 'source_address': '0.0.0.0' 24} 25 26ffmpeg_options = { 27 'options': '-vn' 28} 29 30ytdl = youtube_dl.YoutubeDL(ytdl_format_options) 31 32 33class YTDLSource(discord.PCMVolumeTransformer): 34 def __init__(self, source, *, data, volume=0.5): 35 super().__init__(source, volume) 36 37 self.data = data 38 39 self.title = data.get('title') 40 self.url = data.get('url') 41 42 @classmethod 43 async def from_url(cls, url, *, loop=None, stream=False): 44 loop = loop or asyncio.get_event_loop() 45 data = await loop.run_in_executor(None, lambda: ytdl.extract_info(url, download=not stream)) 46 47 if 'entries' in data: 48 49 data = data['entries'][0] 50 51 filename = data['url'] if stream else ytdl.prepare_filename(data) 52 return cls(discord.FFmpegPCMAudio(filename, **ffmpeg_options), data=data) 53 54 55bot = commands.Bot(command_prefix=commands.when_mentioned_or("_"), 56 description='Relatively simple music bot example') 57 58 59@bot.event 60async def on_ready(): 61 print('Logged in as {0} ({0.id})'.format(bot.user)) 62 print('------') 63 64 65@bot.event 66async def on_message(message): 67 68 if message.content.startswith("_p "): 69 await message.author.voice.channel.connect() 70 message.content=message.content.replace("_p ","") 71 async with message.channel.typing(): 72 player = await YTDLSource.from_url(message.content, loop=asyncio.get_event_loop()) 73 message.author.guild.voice_client.play(player, after=lambda e: print( 74 'Player error: %s' % e) if e else None) 75 await message.channel.send('Now playing: {}'.format(player.title)) 76 77 if message.content.startswith("_dis"): 78 await message.author.guild.voice_client.disconnect()

試したこと

ここに問題に対して試したことを記載してください。

補足情報(FW/ツールのバージョンなど)

ここにより詳細な情報を記載してください。

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

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

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

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

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

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問