From 7143341e7f655f987f7f5f13398b6d42103ed376 Mon Sep 17 00:00:00 2001 From: Xavier Mitault Date: Tue, 17 Sep 2024 18:09:21 +0100 Subject: [PATCH] Fix datetime localize --- worldtimezone/__main__.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/worldtimezone/__main__.py b/worldtimezone/__main__.py index 114794a..dd9cb29 100644 --- a/worldtimezone/__main__.py +++ b/worldtimezone/__main__.py @@ -163,14 +163,19 @@ async def convertIt( ctx: lightbulb.SlashContext, hour: int, minute: int, day: int, month: int, year: int ) -> None: message = "" + user_info = bot.d.data.get_member(ctx.guild_id, ctx.user.id) + if "tz" not in user_info: + await ctx.respond("Please set your timezone first") + return for u in bot.d.data.get_members_list(ctx.guild_id): - member = bot.d.data.get_member(ctx.guild_id, u) - if "tz" in member: + member_info = bot.d.data.get_member(ctx.guild_id, u) + if "tz" in member_info: user_ = ctx.bot.cache.get_member(ctx.guild_id, int(u)) now = datetime.datetime( year=year, month=month, day=day, hour=hour, minute=minute ) - new_tz = pytz.timezone(member["tz"]) + now = pytz.timezone(user_info["tz"]).localize(now) + new_tz = pytz.timezone(member_info["tz"]) new_now = now.astimezone(new_tz) message += f"**{user_.display_name}**: {new_now}\n" await ctx.respond(message)