python-3.x - Discord.Py 删除许多特定消息
问题描述
我有一个发送消息(msg)的函数,一旦用户对该消息做出反应,它就会被删除。
该消息应该出现多次,我遇到的问题是一旦用户对其中一条消息做出反应,所有这些消息都会被删除。
我怎样才能使被删除的消息也是用户反应的消息,而不是所有消息?
async def colorpop(ctx):
chance= random.randint(0,10)
if chance > 7:
picker = random.randint(1,3)
if picker == 1:
color="red"
elif picker == 2:
color="green"
elif picker == 3:
color="blue"
embed = discord.Embed (
title="New Color",
description="React to get this color"
)
msg = await ctx.channel.send(embed=embed)
await msg.add_reaction('')
def check(reaction, user):
return str(reaction.emoji) == '' and user != bot.user
try:
reaction, user = await bot.wait_for('reaction_add', timeout=timer, check=check)
await msg.delete()
await ctx.send("You got the color!")
except asyncio.TimeoutError:
解决方案
推荐阅读
- python - 表单清理方法 vs 模型清理方法 vs 模型字段验证器
- c++ - 如何检查 std::vector 的调整大小是否获得了适当的内存
- python - 有没有办法将 RASA_NLU 配置从 Visual c++ 14.0 更改为 MinGW
- laravel - Laravel - belongsTo 关系的条件
- javascript - 在 Windows 上滚动在最近的选择器上添加类
- django - 'using' 是此函数的无效关键字参数 (serializer.save(using='tableNew'))
- asp.net - ASP.NET Core Web API 如何临时保存已验证的电话号码
- python - 按列任意排序矩阵
- javascript - 画布绘图在放大/缩小时消失
- python - 如何在断点处多次重启长python脚本而不重新运行