データベース接続時の例外処理を追加
This commit is contained in:
parent
f7f7033ea5
commit
4ecf209e7e
1 changed files with 12 additions and 10 deletions
14
dislocker.py
14
dislocker.py
|
@ -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"}
|
||||
|
||||
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("エクスポートに失敗しました。")
|
||||
|
||||
|
||||
dislocker = DL()
|
||||
if dislocker["result"] == "ok":
|
||||
intents = discord.Intents.default()
|
||||
intents.message_content = True
|
||||
|
||||
dislocker = DL()
|
||||
bot = Bot(intents=intents)
|
||||
bot.run(dislocker.server_config['bot']['token'])
|
||||
|
|
Loading…
Reference in a new issue