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. :)