-1

I coded my bot to DM the user every 10 minutes when they say a specific command. I also coded my bot to stop sending the DMs when the user says the command "pp!deactivate." The only problem is that the bot won't send the DM to the user. I would appreciate it very much if someone helped me. My code is shown below.

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

What's supposed to happen:

When the user reacts with 1️⃣, the bot will DM the user every ten minutes. When the user says the command "pp!deactivate" and also react with the , the bot will then stop DMing the user. I just can't figure out why the bot is not DMing the user after the user reacts with 1️⃣.

Thank you in advanced. :)

Phiflo
  • 11
  • Please do not post the [same question](https://stackoverflow.com/questions/67680154/how-do-i-make-the-repeat-function-work-for-my-discord-bot) twice. If your question wasn't answered by one of the answers there, do go and ask how you can fix it instead of making a new question – 12944qwerty May 25 '21 at 23:25
  • 1
    Does this answer your question? [Python - DM a User Discord Bot](https://stackoverflow.com/questions/52343245/python-dm-a-user-discord-bot) – exe May 25 '21 at 23:45
  • Look why don't you use the wait for command. This is like a reaction_add but for that specific message only. Look in [Docs](https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.Bot.wait_for) – Alpha Wolf Gamer May 26 '21 at 04:39

1 Answers1

1

You can use wait_for and on_reaction_add. You can also check this question with a similar problem to yours. You can do member.send() to send a message to a user through DM

Emir Sürmen
  • 884
  • 3
  • 14
  • 33