discord.pyのclient.runについて

前提

pythonでdiscord.pyを使用し,チャットbotを作ろうとしています
オウム返しの機能を実装中に以下のエラーメッセージが発生しました。

実現したいこと

botを起動させてオウム返しができるようにする

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

RuntimeError Traceback (most recent call last) Cell In [1], line 22 19 if message.content.startswith('$hello'): 20 await message.channel.send('Hello!') ---> 22 client.run('MTAyNzIwNjEzMzk5MzE4NTM1MA.GnWQZv.kkA4Nu6QBYfChqyB029HjwosaCZPDLxu0c-wCA') File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py:828, in Client.run(self, token, reconnect, log_handler, log_formatter, log_level, root_logger) 820 utils.setup_logging( 821 handler=log_handler, 822 formatter=log_formatter, 823 level=log_level, 824 root=root_logger, 825 ) 827 try: --> 828 asyncio.run(runner()) 829 except KeyboardInterrupt: 830 # nothing to do here 831 # `asyncio.run` handles the loop cleanup 832 # and `self.start` closes all sockets and the HTTPClient instance. 833 return File ~\AppData\Local\Programs\Python\Python310\lib\asyncio\runners.py:33, in run(main, debug) 9 """Execute the coroutine and return the result. 10 11 This function runs the passed coroutine, taking care of (...) 30 asyncio.run(main()) 31 """ 32 if events._get_running_loop() is not None: ---> 33 raise RuntimeError( 34 "asyncio.run() cannot be called from a running event loop") 36 if not coroutines.iscoroutine(main): 37 raise ValueError("a coroutine was expected, got {!r}".format(main)) RuntimeError: asyncio.run() cannot be called from a running event loop

該当のソースコード

python

# This example requires the 'message_content' intent. import discord intents = discord.Intents.default()intents.message_content = True client = discord.Client(intents=intents) @client.eventasync def on_ready(): print(f'We have logged in as {client.user}') @client.eventasync def on_message(message): if message.author == client.user: return if message.content.startswith('$hello'): await message.channel.send('Hello!') client.run

試したこと

アプデの影響によりintent部分の変更は直したのですが,clientの部分の直し方がわかりません
asyncioやawaitを使用するそうなのですが上手くいきませんでした

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

python 3.10.5
jupyternotebook を使用

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

コメントを投稿

0 コメント