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

2024-05-18 10:52:40 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我是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()

应该发生什么:

当用户对消息作出反应时(我没有显示消息代码,因为它没有问题),我的机器人会告诉用户“每十分钟提醒一次”。然后机器人会等待十分钟,然后再次提醒用户“提醒你停止拖延!”它将重复这个过程,除非用户说“pp!remove”,否则我就是无法让重复功能工作

提前感谢您。:)


Tags: 代码用户yousend消息if定义bot
1条回答
网友
1楼 · 发布于 2024-05-18 10:52:40

这确实会满足你的要求,但这永远不会退出。不知何故,您需要让您的“stop this!”命令设置一个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!')

相关问题 更多 >