[text] 1

Viewer

  1. import asyncio
  2. from datetime import datetime
  3.  
  4. # Definir función para enviar mensaje en un momento específico
  5. async def send_announcement(text, fecha_final, bot):
  6.     while datetime.now() < fecha_final:
  7.         # Esperar hasta el momento programado
  8.         await asyncio.sleep(1)
  9.         channel = await bot.fetch_channel(1088553275227377705)
  10.         await channel.send(text)
  11.         
  12.  
  13. # Definir evento cuando el bot recibe un mensaje
  14. async def rem(ctx, message, hour, minutes, day, month, bot):
  15.     # Separar los argumentos del mensaje
  16.     print("Program")
  17.     # Crear objeto datetime con la fecha y hora especificadas
  18.     fecha_inicial = datetime.now()
  19.     print("Inicial:", fecha_inicial)
  20.     fecha_final = datetime(2023, 3, 24, 18, 40)
  21.     print("Final:", fecha_final)
  22.     # Calcular el tiempo restante hasta la fecha y hora especificadas
  23.     time_left = fecha_final - fecha_inicial
  24.     print(time_left)
  25.     text = message
  26.     # Iniciar temporizador para enviar el mensaje en la fecha y hora especificadas
  27.     asyncio.get_event_loop().create_task(send_announcement(text, fecha_final, bot))

Editor

You can edit this paste and save as new:


File Description
  • 1
  • Paste Code
  • 24 Mar-2023
  • 1.09 Kb
You can Share it: