discord.py-rewrite - 如何检查 discord.py 中的反应内容?
问题描述
我正在创建一个票务系统。我想用/close
命令确认。但我该怎么做?我用 if 语句尝试了它,但它没有用。这就是我所拥有的:
@bot.command(name='Close', aliases=['close'])
async def close(ctx):
if ctx.message.channel.name.startswith('ticket'):
msg = 'The ticket is closed. If you aren\'t done yet react to this message with , if you are react with ️'
embed = discord.Embed(title='Closed ticket', description=msg)
message = await ctx.send(content=None, embed=embed)
await message.add_reaction('')
await message.add_reaction('️')
await ctx.message.channel.set_permissions(ctx.author, send_messages=False)
reaction = await bot.wait_for('reaction')
if reaction.content == '️':
countdown = await ctx.send('**Ticket will be closed in 10 seconds**')
await asyncio.sleep(1)
await countdown.edit(content='**Ticket will be closed in 9 seconds**')
await asyncio.sleep(1)
await countdown.edit(content='**Ticket will be closed in 8 seconds**')
await asyncio.sleep(1)
await countdown.edit(content='**Ticket will be closed in 7 seconds**')
await asyncio.sleep(1)
await countdown.edit(content='**Ticket will be closed in 6 seconds**')
await asyncio.sleep(1)
await countdown.edit(content='**Ticket will be closed in 5 seconds**')
await asyncio.sleep(1)
await countdown.edit(content='**Ticket will be closed in 4 seconds**')
await asyncio.sleep(1)
await countdown.edit(content='**Ticket will be closed in 3 seconds**')
await asyncio.sleep(1)
await countdown.edit(content='**Ticket will be closed in 2 seconds**')
await asyncio.sleep(1)
await countdown.edit(content='**Ticket will be closed in 1 second**')
await asyncio.sleep(1)
await ctx.message.channel.delete()
if reaction.content == '':
await ctx.send('**Ticket reopened**')
await ctx.message.channel.set_permissions(ctx.autor, send_messages=True)
else:
await ctx.send('This isnt a ticket')
我什至没有收到任何错误?
解决方案
在等待添加反应时,您应该使用"reaction_add"
而不是仅"reaction"
:
@bot.command(...)
async def close(ctx):
# Code
# A check is usually encouraged when in a public channel,
# but for a private channel with just one or two members, it should be fine
reaction, user = await bot.wait_for("reaction_add")
# Do some stuff
两个值实际上是从 this 返回的wait_for
,如文档的示例-reaction
和user
.
此外,该discord.Reaction
对象没有content
属性。
您实际上会寻找str(reaction)
:
参考:
推荐阅读
- ruby-on-rails - Graphql:找不到生成器“graphql:安装”
- r - 如何修复:doTryCatch(return(expr), name, parentenv, handler) 中的错误:输入/输出错误
- python - 如何在套索回归或任何其他方法中生成系数 >0?
- angular - 如何有条件地添加垫升按钮?
- date - 带日期的 awk 从 unix 时间转换为日期
- c - 套接字发送有时只能在无限循环中工作(C)
- xmobar - 如何格式化字符串输出
- python - Django:有效地从父对象读取子对象
- sql - 数字的格式
- jmeter - 需要验证将从 csv 文件中获取的请求响应并验证