简体   繁体   English

如何使重复的 function 为我的 discord 机器人工作?

[英]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).所以我是 discord.py 的新手,我对 Lua(另一种编码语言)有一点经验。 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."当用户对消息做出反应"1️⃣"时(我没有显示消息代码,因为它没有问题),我的机器人会 DM 用户说“每十分钟提醒你一次”。 The bot will then wait ten minutes and then DMing the user again saying "Reminding you to stop procrastinating."然后,机器人将等待十分钟,然后再次向用户发送 DM,说“提醒你停止拖延”。 It will repeat the process unless the user says "pp!remove" I just can't get the repeat function working.除非用户说“pp!remove”,否则它将重复该过程。我只是无法让重复的 function 工作。

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.命令设置while循环检查的标志。

@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!')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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