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

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

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

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

Python 3.x

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

Q&A

解決済

1回答

2124閲覧

discord.py event loop is closed の解決方法

yuuto33

総合スコア17

Discord

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

Python 3.x

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

0グッド

0クリップ

投稿2023/01/20 12:47

前提

pythonでpaypayの自動受け取りのdiscord bot を作っていますがエラーが出て、進みません

実現したいこと

エラーを解消し、動くようにしたい

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

2023-01-20 21:30:37 INFO discord.client logging in using static token Traceback (most recent call last): File "C:\Users\5122a\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\http.py", line 801, in static_login data = await self.request(Route('GET', '/users/@me')) File "C:\Users\5122a\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\http.py", line 744, in request raise HTTPException(response, data) discord.errors.HTTPException: 401 Unauthorized (error code: 0): 401: Unauthorized The above exception was the direct cause of the following exception: Traceback (most recent call last): File "c:\Users\5122a\Downloads\examples\main.py", line 97, in <module> client.run(token) File "C:\Users\5122a\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 828, in run asyncio.run(runner()) File "C:\Users\5122a\AppData\Local\Programs\Python\Python310\lib\asyncio\runners.py", line 44, in run return loop.run_until_complete(main) File "C:\Users\5122a\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 641, in run_until_complete return future.result() File "C:\Users\5122a\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 817, in runner await self.start(token, reconnect=reconnect) File "C:\Users\5122a\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 745, in start await self.login(token) File "C:\Users\5122a\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 580, in login data = await self.http.static_login(token) File "C:\Users\5122a\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\http.py", line 805, in static_login raise LoginFailure('Improper token has been passed.') from exc discord.errors.LoginFailure: Improper token has been passed. Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x00000182D3766F80> Traceback (most recent call last): File "C:\Users\5122a\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 116, in __del__ self.close() File "C:\Users\5122a\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 108, in close self._loop.call_soon(self._call_connection_lost, None) File "C:\Users\5122a\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 745, in call_soon self._check_closed() File "C:\Users\5122a\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 510, in _check_closed raise RuntimeError('Event loop is closed') RuntimeError: Event loop is closed

該当のソースコード

python

1import re,asyncio 2import package.paypaypublic as ppub 3import discord 4from discord import app_commands 5from discord.ui import Modal,text_input 6token="token"#BotのTokenを入力。 7 8 9intents = discord.Intents.default() 10intents.message_content=True 11client = discord.Client(intents=intents) 12tree = app_commands.CommandTree(client) 13 14 15 16 17@client.event 18async def on_ready(): 19 print("起動。") 20 await tree.sync() 21# 22@client.event 23async def on_message(message): 24 # メッセージ送信者がBotだった場合は無視する 25 if message.author.bot: 26 return 27 if re.search(r'https://pay.paypay.ne.jp',message.content) : 28 p_link=re.findall(r'https://pay.paypay.ne.jp/+\w+\w',message.content)[0].replace("https://pay.paypay.ne.jp/","") 29 print(p_link) 30 c_channel = message.channel 31 c_author=message.author 32 def check(m): 33 return m.author == c_author and m.channel == c_channel 34 pcode_umu=ppub.check_pcode(p_link) 35 if pcode_umu=="SUCCESS": 36 await message.channel.send("使用済リンクです。") 37 return 38 elif pcode_umu=="Cannot find P2P link": 39 await message.channel.send("受け取りリンクが見つかりません。") 40 return 41 elif pcode_umu=="パスワード付き": 42 await message.channel.send("パスワード付きリンクを検知しました。"+'\n'+"20秒以内に半角で4桁のパスワードを入力してください 例:0417"+'\n'+"これを拒否する場合は拒否と入力してください。") 43 try: 44 msg = await client.wait_for('message',check=check,timeout=20) 45 if msg.content=="拒否": 46 await message.channel.send("拒否されました。") 47 return 48 49 try: 50 ererer=int(msg.content) 51 except: 52 await message.channel.send("無効なパスワードです。") 53 return 54 55 pcode_data=(msg.content) 56 except asyncio.TimeoutError: 57 await message.channel.send("タイムアウトしました。") 58 return 59 elif pcode_umu=="パスワード無し": 60 pcode_data="1919" 61 62 jido_kessai=ppub.start(p_link,pcode_data) 63 try: 64 dataaaaaa=jido_kessai[0] 65 if type(jido_kessai)==list:uketori_st=True 66 else:uketori_st=False 67 except:uketori_st=False 68 if uketori_st == True: 69 embed = discord.Embed( # Embedを定義する 70 title=f"{jido_kessai[0]}さんから受け取り",# タイトル 71 description=f"金額:{jido_kessai[2]}円", 72 color=0x00ff00 73 ) 74 embed.set_thumbnail(url=jido_kessai[1]) 75 await message.channel.send(embed=embed) 76 77 78 79 80class Md(Modal): 81 a = text_input.TextInput(label='PayPay受け取りリンク', placeholder='https://pay.paypay.ne.jp/HAudjw45', max_length=35, required=True) 82 b = text_input.TextInput(label='パスコード', style=discord.TextStyle.short, required=True,max_length=4,placeholder="1234") 83 def __init__(self): 84 super().__init__(title='PayPay受け取り') 85 86 async def on_submit(self, interaction:discord.Interaction): 87 paypay_link=self.a.value.replace("https://pay.paypay.ne.jp/","") 88 paypay_passcode=self.b.value 89 pcode_umu=ppub.check_pcode(paypay_link) 90 if pcode_umu=="Cannot find P2P link": 91 await interaction.response.send_message("そのPayPayリンクは存在しません。",ephemeral=True) 92 return 93 #pp_author=interaction.user 94 uketori=ppub.start(paypay_link,paypay_passcode) 95 #めんどくさかったので簡単に。 96 try: 97 dataaaaaa=uketori[0] 98 if type(uketori)==list:uketori_st=True 99 else:uketori_st=False 100 except:uketori_st=False 101 if uketori_st == True: 102 embed = discord.Embed( # Embedを定義する 103 title=f"{uketori[0]}さんから受け取り",# タイトル 104 description=f"金額:{uketori[2]}円", 105 color=0x00ff00 106 ) 107 embed.set_thumbnail(url=uketori[1]) 108 await interaction.response.send_message(embed=embed,ephemeral=True) 109 else: 110 if uketori=="パスコードが違います": 111 await interaction.response.send_message("失敗しました。パスコードが間違っていました。お金は2日ほど後に返ってくるのでご安心ください。",ephemeral=True) 112 else: 113 print(uketori) 114 await interaction.response.send_message("失敗しました。リンクが不正だったり、システムエラーが起きていたりしている可能性があります。",ephemeral=True) 115 116 117 118@tree.command(name="send_paypay",description="PayPayリンクを送って支援できます。") 119async def test(interaction: discord.Interaction): 120 await interaction.response.send_modal(Md()) 121 122 123client.run(token)

試したこと

tokenの打ち間違いと思い、再度コピーして入力した

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

python 3.1.0
vscode
discord.py2.1.0

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

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

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

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

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

LaZy

2023/07/22 08:43

すみません package moduleが見つからないとエラーが出ますどうしたらいいでしょうか?
pecop

2023/07/26 23:37

pipから再インスコ?
guest

回答1

0

ベストアンサー

以下は上記のエラーの重要なところをピックアップしたものです。

py

11 2 raise HTTPException(response, data) 3discord.errors.HTTPException: 401 Unauthorized (error code: 0): 401: Unauthorized 4 52 6 File "C:\Users\5122a\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\http.py", line 805, in static_login 7 raise LoginFailure('Improper token has been passed.') from exc 8discord.errors.LoginFailure: Improper token has been passed.

※1
401 Unauthorized とはこの場合、discord側から(botを)受け入れられなかった、つまり認証されなかったということです。

※2
LoginFailure とはこの場合、ログイン出来ていないという事になります。

Improper token has been passed不適切なトークンが渡されました
要はtokenが間違っているのかもしれません。ポータル側からトークンをリセットするか、botを新しく作り直すかしてみてはいかがでしょうか。


P.S. 質問コメントに広告とありますがどこが広告なのか。。。

投稿2023/01/22 23:14

pecop

総合スコア409

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

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

yuuto33

2023/01/23 02:42

ありがとうございます。 新しくbotを作り直す事で解決しました 広告ではないですよね、、指摘受けたのですこし不安でした笑
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問