L
L
Lol Likovic2020-07-19 13:46:51
Python
Lol Likovic, 2020-07-19 13:46:51

How to make the bot write to the channel on time?

So my code:

@tasks.loop(seconds=20)
async def timer_notify():
    await client.wait_until_ready()
    print('lol')
    cur_time = localtime(time())
    for user_id,counter in user_counter.items():
        global msg
        user = client.get_user(user_id)
        msg = msg+' >> ' + user.name + ': ' + str(counter)  + '\n'
    msg = 'Статистика:\n'


So, how to make the bot write to the channel? That is, he writes to the command line, but I can’t figure out how to make him write to the channel

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
shurshur, 2020-07-19
@Lolik666

You need to somehow find out the id of the desired channel. The easiest way: in the Discord client, RMB->Copy ID.
Further:

my_channel = client.get_channel(ID_нужного_канала)
await my_channel.send('Сообщение')

A
Alexander, 2020-07-19
@Alexandre888

well, replace it printwithmessage.channel.send

K
Kaktys_DH, 2020-07-19
@Kaktys_DH

@tasks.loop(seconds=20)
async def timer_notify():
await client.wait_until_ready()
message.channel.send('lol')
cur_time = localtime(time())
for user_id,counter in user_counter.items():
global msg
user = client.get_user(user_id)
msg ​​= msg+' >> ' + user.name + ': ' + str(counter) + '\n'
msg = 'Stats:\n'
PS find one difference, code works )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question