From 72abc43db8f732743c65d6f6a820369ab8665766 Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 4 Feb 2026 16:19:22 +0100 Subject: more asynchronous work and other minor improvements --- main.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'main.py') diff --git a/main.py b/main.py index efeb3a2..3ee86b2 100644 --- a/main.py +++ b/main.py @@ -8,6 +8,7 @@ import os import sys import json import asyncio +import aiofiles import discord from discord.ext import commands from dotenv import load_dotenv @@ -28,27 +29,29 @@ asyncio.set_event_loop(loop) bot = commands.Bot(intents=discord.Intents.all(), loop=loop) +settings = "settings.json" + @bot.event async def on_ready(): logger.info("ŁUKASZ SPERMA AKTYWACJA") # send the message to channel ID channel = bot.get_channel(1081667823799111804) await channel.send("ŁUKASZ SPERMA AKTYWACJA") - if not os.path.exists('settings.json'): - with open('settings.json', 'w') as f: + if not os.path.exists(settings): + async with aiofiles.open(settings, 'w') as f: json.dump({ 'volume': 1.0, 'audio_paths': ['audio', 'music', 'sounds'] }, f) - if os.path.exists('settings.json'): + if os.path.exists(settings): try: - with open('settings.json') as f: + async with aiofiles.open(settings) as f: data = json.load(f) assert 'volume' in data and isinstance(data['volume'], float) assert 'audio_paths' in data and isinstance(data['audio_paths'], list) except (json.JSONDecodeError, AssertionError) as error: logger.error(f"Error loading settings.json: {error}") - with open('settings.json', 'w') as f: + async with aiofiles.open(settings, 'w') as f: json.dump({ 'volume': 1.0, 'audio_paths': ['audio', 'music', 'sounds'] @@ -69,7 +72,7 @@ if __name__ == "__main__": 'cogs.downloader', 'cogs.say', 'cogs.jarvis', - 'cogs.music.play', + 'cogs.music.play_commands', 'cogs.music.stop', 'cogs.music.join', ] -- cgit v1.2.3