A
A
Anton Anton2020-05-15 12:01:52
Python
Anton Anton, 2020-05-15 12:01:52

How to send messages to a text channel by timing?

Hi friends! For personal purposes, I'm trying to create a discord bot in python. I downloaded the discord py library, created the bot itself on the server. Essence of the question: It is
necessary that the bot sends messages to the text channel on the server according to the timing (without user intervention).

I want to say right away that I am a complete noob in python programming, and I have trouble with English. As a result, at the moment, studying the documentation for the library is not possible.

Please help me to sort out this issue.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
Nazar Tropanets, 2020-05-15
@monolitHC

Use the datetime module

import datetime
import time
 
starttime=time.time() 

while True: 
  now = datetime.datetime.now()
  now = now.strftime('%H:%M')
  if now == '13:00':
    pass
        #отсылка сообщения
  time.sleep(60 - ((time.time() - starttime) % 60))

just pass write the code to send the message and if you need to replace 13:00 with another time
you just need to import the discord library and add the code to send
ps forgot to add that everything should work asynchronously otherwise only while True will be executed,
use asyncio, in Russian YouTube has a lot of video tutorials on this library

Z
zexer, 2020-05-15
@zexer

Probably the easiest way is to schedule a file to run.
That is, you have a .py file that sends a message to a channel, schedule this file to run.
Google the task scheduler in Windows, it's very simple there.

P
pythonist1234, 2020-05-15
@pythonist1234

Use sleep(time).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question