A
A
ah0R2021-09-04 09:32:05
Python
ah0R, 2021-09-04 09:32:05

How to make message time with timezone?

With code like this:

@bot.event
async def on_ready():
    DiscordComponents(bot)
    await bot.change_presence(activity=discord.Game(name="Monro FamQ"))
    current_time = datetime.now().time()
    res =  bot.get_channel(882269213807497327)
    log = discord.Embed(title = '',description = '', colour = 0xFFFF00)
    log.set_thumbnail(url = f'https://media.discordapp.net/attachments/716571065270140938/880854910005047366/-7.png?width=701&height=701')
    log.add_field(name="", value= '', inline=True)
    log.set_footer(icon_url = 'https://media.discordapp.net/attachments/716571065270140938/880854176735854622/-6.png?width=701&height=701', 
        text = "Сегодня в %d:%d" % (current_time.hour, current_time.minute))
    await res.send(
                      embed = log)
    print("Бот включен")

Everyone in the bot message sees my time + the first 0 is not displayed in the first 10 minutes (screen below)
613312d28345f988695479.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
shurshur, 2021-09-04
@ah0R

You don’t need to compose the string time from the components yourself, there are ready-made methods. Discord does not provide information about the user’s time zone, so it’s impossible to show everyone his time as text. But you can add a timestamp to embed, then everyone will receive an individual time, taking into account their time zone:
datetime.datetime.now().strftime('%H:%M')

embed = discord.Embed(title='test',timestamp=datetime.datetime.utcnow())

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question