当我的机器人 DM 对特定消息做出反应时,如何让他们成为用户?

时间:2021-05-25 23:22:15

标签: python discord discord.py

当用户说出特定命令时,我每 10 分钟将我的机器人编码为 DM。我还对我的机器人进行了编码,以在用户说出命令“pp!deactivate”时停止发送 DM。唯一的问题是机器人不会将 DM 发送给用户。如果有人帮助我,我将不胜感激。我的代码如下所示。

import discord
import asyncio
import time
from discord.ext import commands

@bot.command()
async def create(ctx):
    createEmbed = discord.Embed(title='When would you like me to remind you?', description='1️⃣ Every 10 minutes\n2️⃣ Every 30 minutes\n3️⃣ Every hour')
    msg = await ctx.send(embed=createEmbed)
    await msg.add_reaction('1️⃣')
    await msg.add_reaction('2️⃣')
    await msg.add_reaction('3️⃣')

@bot.event # reaction to the create command
async def on_reaction_add(reaction, user):
    global activate
    activate = False
    emoji = reaction.emoji

    if user.bot:
        return

    if emoji == '1️⃣':

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

@bot.command()
async def deactivate(ctx):
    deactivateEmbed = discord.Embed(title='Would you like me to stop reminding you?', description='✅ Stop reminding you\n❌ Cancel')
    msg = await ctx.send(embed=deactivateEmbed)
    await msg.add_reaction('✅')
    await msg.add_reaction('❌')

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

    if user.bot:
        return

    if emoji == '✅':
        activate = False
        await user.send('I will stop reminding you now.')
        msg.cancel()

    elif emoji == '❌':
        await user.send('I will continue reminding you.')
        cancel()

应该发生什么:

当用户对 1️⃣ 做出反应时,机器人将每十分钟向用户发送 DM。当用户说出命令“pp!deactivate”并用 做出反应时,机器人将停止向用户发送 DM。我只是不明白为什么在用户对 1️⃣ 做出反应后,机器人没有向用户发送 DM。

先谢谢你。 :)

1 个答案:

答案 0 :(得分:1)

您可以使用 wait_foron_reaction_add。您也可以检查 this question 是否存在与您类似的问题。您可以执行 member.send() 通过 DM 向用户发送消息