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

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

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

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

Q&A

解決済

1回答

1708閲覧

RuntimeError discord bot

Useer-Useer.

総合スコア6

Python 3.x

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

0グッド

0クリップ

投稿2020/03/03 05:51

前提・実現したいこと

ここに質問の内容を詳しく書いてください。
pythonでdiscordのbotを作ろうとしてた時、ほかの人は実行できるコードがエラーを吐き続けています

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

RuntimeError Traceback (most recent call last) ~\Anaconda3\envs\discordbot\lib\site-packages\discord\client.py in run(self, *args, **kwargs) 630 try: --> 631 loop.run_forever() 632 except KeyboardInterrupt: ~\Anaconda3\envs\discordbot\lib\asyncio\base_events.py in run_forever(self) 524 if self.is_running(): --> 525 raise RuntimeError('This event loop is already running') 526 if events._get_running_loop() is not None: RuntimeError: This event loop is already running During handling of the above exception, another exception occurred: RuntimeError Traceback (most recent call last) ~\Anaconda3\envs\discordbot\lib\site-packages\discord\client.py in _cleanup_loop(loop) 91 try: ---> 92 _cancel_tasks(loop) 93 if sys.version_info >= (3, 6): ~\Anaconda3\envs\discordbot\lib\site-packages\discord\client.py in _cancel_tasks(loop) 76 ---> 77 loop.run_until_complete(asyncio.gather(*tasks, return_exceptions=True)) 78 log.info('All tasks finished cancelling.') ~\Anaconda3\envs\discordbot\lib\asyncio\base_events.py in run_until_complete(self, future) 569 try: --> 570 self.run_forever() 571 except: ~\Anaconda3\envs\discordbot\lib\asyncio\base_events.py in run_forever(self) 524 if self.is_running(): --> 525 raise RuntimeError('This event loop is already running') 526 if events._get_running_loop() is not None: RuntimeError: This event loop is already running During handling of the above exception, another exception occurred: RuntimeError Traceback (most recent call last) <ipython-input-8-19ac8c304d6a> in <module> 21 22 # Bot起動 ---> 23 client.run('my_token') ~\Anaconda3\envs\discordbot\lib\site-packages\discord\client.py in run(self, *args, **kwargs) 635 future.remove_done_callback(stop_loop_on_completion) 636 log.info('Cleaning up tasks.') --> 637 _cleanup_loop(loop) 638 639 if not future.cancelled(): ~\Anaconda3\envs\discordbot\lib\site-packages\discord\client.py in _cleanup_loop(loop) 95 finally: 96 log.info('Closing the event loop.') ---> 97 loop.close() 98 99 class _ClientEventTask(asyncio.Task): ~\Anaconda3\envs\discordbot\lib\asyncio\selector_events.py in close(self) 86 def close(self): 87 if self.is_running(): ---> 88 raise RuntimeError("Cannot close a running event loop") 89 if self.is_closed(): 90 return RuntimeError: Cannot close a running event loop

該当のソースコード

python

1import discord 2@client.event 3async def on_ready(): 4 msg = "TEST Botです.よろしく" 5 await client.send_message(text_chat,msg) 6 7# こんにちはメッセージ 8@client.event 9async def on_message(message): 10 if message.content.startswith("こんにちは"): 11 if client.user != message.author: 12 msg = "こんにちは " + message.author.name + "さん!" 13 await client.send_message(message.channel, msg) 14 15# メンバのステータスが変更されたら 16@client.event 17async def on_member_update(before, after): 18 if before.status != after.status: 19 msg = after.display_name + " さんが " + str(after.status) + " になりました" 20 await client.send_message(text_chat,msg) 21 22# Bot起動 23client.run('my_token')

試したこと

RuntimeErrorというものをググってみてもよくわからませんでした。
discord.pyを何回かインストールしなおしましたが駄目でした

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

Python version 3.7.6
Anaconda jupyter lab を使ってます
知り合いはこのコードをコピペして起動できました。

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

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

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

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

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

mistn

2020/03/03 06:01

知り合いの人もjupyter labを使ってコードを実行していますか?
Useer-Useer.

2020/03/04 00:28

使ってます。友達と同じ方法で実行しようとするとこのようなメッセージが出ました
guest

回答1

0

ベストアンサー

Can't invoke asyncio event_loop after tornado 5.0 update
これはjupyter notebookのものですがjupyter labでも同様だと思います。

これによるとtornadoというモジュールのバージョンが5.0以上であると問題が起こるようで、解決方法としてバージョンを下げることが挙げられていました。

pip install tornado==4.5.3

これでエラーは出なくなると思います。

ただ、別のモジュールがtornadoの5.0以上を要求している場合がある(私の環境はそうでした)ので安易にバージョンは下げないほうがいいかもしれません。
バージョンを下げるのが不安だなと思った場合はjupyter labを使わずにコマンドプロンプトやターミナルからコードを実行すればいいと思います。

投稿2020/03/04 01:38

mistn

総合スコア1191

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問