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

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

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

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

Q&A

解決済

1回答

841閲覧

AttributeError: 'NoneType' object has no attribute 'stop'

bs_yuuki1

総合スコア13

Python 3.x

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

0グッド

0クリップ

投稿2018/11/25 00:37

編集2018/11/25 01:40

実現したいこと

BOTをVoice Channelから切断
[現在は Join Commandのみ完成]

発生している問題・エラーメッセージ

Ignoring exception in command stop: Traceback (most recent call last): File "C:\Users\T\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\ext\commands\core.py", line 61, in wrapped ret = await coro(*args, **kwargs) File "C:\Users\T\Desktop\Blockgrass-bot-master\command\music.py", line 36, in stop vc_client.stop() AttributeError: 'NoneType' object has no attribute 'stop' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "C:\Users\T\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\ext\commands\bot.py", line 899, in invoke await ctx.command.invoke(ctx) File "C:\Users\T\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\ext\commands\core.py", line 614, in invoke await injected(*ctx.args, **ctx.kwargs) File "C:\Users\T\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\ext\commands\core.py", line 70, in wrapped raise CommandInvokeError(e) from e discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'stop'

該当のソースコード

python

1 @commands.command(name='stop') 2 async def stop(self, ctx): 3 vc_client = ctx.voice_client 4 vc_channel = ctx.author.voice.channel 5 if vc_channel: 6 vc_client.stop() 7 await ctx.send('BOTをVCから切断したよ') 8 if not vc_channel: 9 await ctx.send('Voice ChannelにBOTはいないよ')

試したこと

Voice Channelに参加してもErrorが
[Error内容は 同じ NoneType]

Discord.py/Python Ver

discord.py[1.0.0a] rewrite
python 3.7.1

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

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

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

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

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

can110

2018/11/25 01:19

エラー発生行などが分かるようにTraceback全文を追記くださると回答得られやすくなります。
guest

回答1

0

ベストアンサー

Discord触ったことないので処理を推測しての回答です。
if vc_channel:ならBOTVCから切断していますが、そもそもBOTVCに接続していない場合はvc_clientNoneになっているのではないでしょうか?
よって、処理の意味合い的にはif vc_channel:部分はif vc_client:という判定であるべきかと思います。

投稿2018/11/25 01:50

can110

総合スコア38234

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問