Skip to content

Commit f29bd59

Browse files
committed
fix: discord.py の aiohttp コネクタ上限を解除して内部 HTTP セッションを差し替え
on_ready で patch_discord_aiohttp_limit を実行し、aiohttp.TCPConnector(limit=0) のセッションで bot.http._HTTPClient__session を置換することで接続上限による問題を回避
1 parent 7b56977 commit f29bd59

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

bot.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import threading
2121
import uvicorn
2222
from lib.bot_http_server import app as bot_http_app, set_bot
23+
import aiohttp
2324

2425
load_dotenv()
2526

@@ -72,6 +73,12 @@ async def load_all_cogs():
7273

7374
db = PostgresDB() # データベースクラスのインスタンスを作成
7475

76+
async def patch_discord_aiohttp_limit(bot):
77+
connector = aiohttp.TCPConnector(limit=0)
78+
session = aiohttp.ClientSession(connector=connector)
79+
if hasattr(bot.http, "_HTTPClient__session"):
80+
bot.http._HTTPClient__session = session
81+
7582
async def update_rpc_task():
7683
while True:
7784
try:
@@ -111,6 +118,7 @@ async def restart_rpc_task():
111118
@bot.event
112119
async def on_ready():
113120
print(f'Logged in as {bot.user}')
121+
await patch_discord_aiohttp_limit(bot)
114122

115123
# データベース接続テスト
116124
print("Testing database connection...")

0 commit comments

Comments
 (0)