[Python] Updating values constantly in a function [duplicate]

Discussão em 'Python' iniciado por Stack, Julho 31, 2025.

  1. Stack

    Stack Membro Participativo

    I was trying to create a Discord bot that sends a message on specific time using the code below:

    import discord
    import datetime

    intents = discord.Intents.default()
    intents.message_content = True

    client = discord.Client(intents=intents)

    @client.event
    async def on_ready():
    print(f'We have logged in as {client.user}')

    @client.event
    async def on_message(message):
    if message.author == client.user:
    return

    if datetime.datetime.now().hour == 22 and datetime.datetime.now().minute == 48:
    await message.channel.send('Scheduled on 22:48')

    client.run(TOKEN)


    I believe that the problem occurs since datetime.datetime.now() isn't updated. I tried to update the value by making a function and ran it as a, but I couldn't pass the arguments to the on_message. Is there any ways that I can update this value in the function?

    Continue reading...

Compartilhe esta Página