我正在创建票务系统。我想用/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')
我什至没有得到任何错误?
答案 0 :(得分:0)
在等待添加反应时,应使用from collections import Counter
c = Counter()
for j in data_list:
name = j[2]
goal = int(j[3])
c[name] += goal
print(c.most_common()) # -> [('Khan', 3), ('Daniel', 1)]
而不是"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
返回了两个值,如documentation's example-wait_for
和reaction
所示。
此外,user
对象没有discord.Reaction
属性。
实际上,您实际上是在寻找content
:
参考: