简体   繁体   中英

How do I make the repeat function work for my discord bot?

So I am new to discord.py and I have a little bit of experience on Lua (another coding language). I am trying to make my bot repeat what its been doing after waiting ten minutes. But the error tells me that "repeat" is not defined. I know what defining repeat is but I don't know what to define it to or what to import. My code is shown below.

@bot.event
async def on_reaction_add(reaction, user):
    emoji = reaction.emoji

    if user.bot:
        return

    if emoji == '1️⃣':

        await user.send('Reminding you every ten minutes.')
        await asyncio.sleep(600)
        await user.send('Reminding you to stop procrastinating!')
        repeat()

What's supposed to happen:

When the user reacts with "1️⃣" to the message (I didn't show the message code because there's no problem with it), My bot will DM the user saying "Reminding you every ten minutes." The bot will then wait ten minutes and then DMing the user again saying "Reminding you to stop procrastinating." It will repeat the process unless the user says "pp!remove" I just can't get the repeat function working.

Thank you in advanced. :)

This will literally do what you asked, but this will never exit. Somehow, you'll need to have your "stop this!" command set a flag that the while loop checks.

@bot.event
async def on_reaction_add(reaction, user):
    emoji = reaction.emoji

    if user.bot:
        return

    if emoji == '1️⃣':

        await user.send('Reminding you every ten minutes.')
        while True:
            await asyncio.sleep(600)
            await user.send('Reminding you to stop procrastinating!')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM