[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, date_time, bot):
  6.     while datetime.now() < date_time:
  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.     date_time = datetime(datetime.now().year, month, day, hour, minutes)
  19.     # Calcular el tiempo restante hasta la fecha y hora especificadas
  20.     time_left = (date_time - datetime.now()).total_seconds()
  21.     print(time_left)
  22.     text = message
  23.     # Iniciar temporizador para enviar el mensaje en la fecha y hora especificadas
  24.     asyncio.get_event_loop().create_task(send_announcement(text, date_time, bot))

Editor

You can edit this paste and save as new:


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