データベース接続時の例外処理を追加

This commit is contained in:
suti7yk5032 2024-07-07 15:43:43 +09:00
parent f7f7033ea5
commit 4ecf209e7e

View file

@ -53,9 +53,14 @@ class DL():
os.mkdir(self.export_dir_path)
except:
print("export ディレクトリを作成できませんでした。")
try:
self.db = psycopg2.connect(f"host={self.server_config['db']['host']} dbname={self.server_config['db']['db_name']} port={self.server_config['db']['port']} user={self.server_config['db']['username']} password={self.server_config['db']['password']}")
result = {"result": "ok"}
except (Exception) as error:
print("データベースに接続できません。\nエラー内容\n" + error)
result = {"result": "error"}
self.db = psycopg2.connect(f"host={self.server_config['db']['host']} dbname={self.server_config['db']['db_name']} port={self.server_config['db']['port']} user={self.server_config['db']['username']} password={self.server_config['db']['password']}")
return result
class Bot(discord.Client):
@ -232,8 +237,6 @@ class Bot(discord.Client):
return result
async def on_ready(self):
print("ログイン成功")
@ -308,10 +311,9 @@ class Bot(discord.Client):
elif export["result"] == "export_error":
await message.channel.send("エクスポートに失敗しました。")
intents = discord.Intents.default()
intents.message_content = True
dislocker = DL()
bot = Bot(intents=intents)
bot.run(dislocker.server_config['bot']['token'])
if dislocker["result"] == "ok":
intents = discord.Intents.default()
intents.message_content = True
bot = Bot(intents=intents)
bot.run(dislocker.server_config['bot']['token'])