how can I check if before.timed_out_until is before present or empty?

this is a stripped down version of my file

the code doesn’t work IF:
a member got timed out before and that timeout ended naturally.
the bot was running for the first time. (somewhat fixed it by getting entries in on_ready() and still sometimes doesn’t work)

import discord
import discord.ext
from discord.ext import commands
from discord.ext.commands import Bot
from datetime import datetime

intents = discord.Intents.all()
client = discord.Client(intents=intents)
bot = Bot(command_prefix=".", case_insensitive=True, intents=intents)

@bot.event
async def on_ready():
    print("Bot Hazır" + " " + str(bot.user))

@bot.event
async def on_member_update(before: discord.Member, after: discord.Member):
    memberroleupdate = "AuditLogAction.member_role_update"
    memberupdate = "AuditLogAction.member_update"
    cid = channel_id
    guild = guild_id 
    async for entry in after.guild.audit_logs(limit=1):
        if str(entry.action) == memberupdate:
            #below prints a date if this user has been timed out before
            #and if the mentioned timeout ended naturally
            print(before.timed_out_until)
            print(after.timed_out_until)
            if before.timed_out_until is None:
                #can't reach here when before.timed_out_until prints date
                if after.timed_out_until is not None:
                    async for entry in after.guild.audit_logs(limit=1, action=discord.AuditLogAction.member_update):
                        if entry.target.id == after.id:
                            channel = await bot.fetch_channel(cid)
                            embed = discord.Embed(title="Timeout log",
                                                  description=f"**{after.mention} ({after.id}) adlı kullanıcı {entry.user.mention} ({entry.user.id}) tarafından susturuldu.nSebep: {entry.reason}**",
                                                  color=discord.Color.blue())
                            embed.set_author(name=f"{after}",
                                             icon_url=f"{after.avatar}")
                            await channel.send(embed=embed)

bot.run("TOKEN")

tried comparing before.timed_out_until with datetime.now() but I wasn’t able to compare two dates
tried setting before.timed_out_until to None manually but I don’t think discord.py works that way

comparing two dates might work but I’m unable to do so

the solution that worked for me:

Changing if after.timed_out_until is not None:

2

from discord import utils

# ...

if if before.timed_out_until is None or before.timed_out_until < utils.utcnow():
    ... # timed_out_until is in the past

1

tried comparing before.timed_out_until with datetime.now()

You’re probably getting the error TypeError: can't compare naive and aware datetimes since the time provided by the Discord API has UTC tzinfo, while the time returned by datetime.now() has no tzinfo. Try this:

from datetime import datetime, UTC


now = datetime.now(UTC)
if before.timed_out_until > now:
    pass

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật