U
U
UniFild4452022-01-16 20:19:12
Python
UniFild445, 2022-01-16 20:19:12

How to make the discord bot send a message every 10 minutes?

I want to make my discord bot send a message every 10 minutes, but I can't do it. I use the discord.py library.
Here is what I have:

@bot.event
async def on_message(ctx):
  message = get_message()
  await bot.get_channel("Привет").send(message)
  await asyncio.sleep(10)
  await bot.get_channel("Привет").send(message)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
shurshur, 2022-01-16
@shurshur

discord.py has its own mechanism for performing regular tasks:

from discord.ext import tasks

@tasks.loop(seconds=600)
async def notify_task():
    await bot.wait_until_ready()
    ... нужные действия

notify_task.start()
bot.run(config.BOT_TOKEN)

But nothing prevents you from running a separate asyncio-task with a loop (and, of course, asyncio.sleep instead of time.sleep) and on your own.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question