3
3
35000sobak2022-01-07 21:49:51
Python
35000sobak, 2022-01-07 21:49:51

How to set a timer for a function in a discord bot?

@bot.command()
async def hello(ctx, *, string): 
    author = ctx.message.author
   
        await ctx.send('Hello')

I want to put the function into a timer and run it about once every 60 seconds, but it complicates everything that there is a ctx argument that is needed to send to the chat, and sending to the chat is necessary for me. Of course, you can make permanent slips with asyncio, but this is not all that, besides, it starts with a command from the discord channel chat. Interested in the question, is it even possible to simply create a function and set a timer, with the ability to send a message to the chat via ctx.send for example?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2022-01-07
@35000sobak

1. There is an example in the documentation .
2. You don't need a context (ctx), you can get the channel object just by its ID . Through it, you can also get a private channel with the user. Once you have a channel object, you can simply write to it .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question