【发布时间】:2021-08-14 05:08:30
【问题描述】:
当用户说出特定命令时,我每 10 分钟向我的机器人编码一次。当用户说出命令“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️⃣ 做出反应后,机器人没有向用户发送消息。
在此先感谢您。 :)
【问题讨论】:
-
请不要发same question两次。如果那里的答案之一没有回答您的问题,请去询问如何解决它而不是提出新问题
-
这能回答你的问题吗? Python - DM a User Discord Bot
-
看看你为什么不使用等待命令。这就像一个 react_add 但仅针对该特定消息。看Docs
标签: python discord discord.py