繁体   English   中英

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

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

所以我是 discord.py 的新手,我对 Lua(另一种编码语言)有一点经验。 我试图让我的机器人在等待十分钟后重复它所做的事情。 但是错误告诉我没有定义“重复”。 我知道定义重复是什么,但我不知道要定义什么或导入什么。 我的代码如下所示。

@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()

应该发生什么:

当用户对消息做出反应"1️⃣"时(我没有显示消息代码,因为它没有问题),我的机器人会 DM 用户说“每十分钟提醒你一次”。 然后,机器人将等待十分钟,然后再次向用户发送 DM,说“提醒你停止拖延”。 除非用户说“pp!remove”,否则它将重复该过程。我只是无法让重复的 function 工作。

提前谢谢你。 :)

这实际上会按照您的要求进行,但这永远不会退出。 不知何故,你需要让你的“停止这个!” 命令设置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