首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何检查discord.py中的反应内容?

如何检查discord.py中的反应内容?
EN

Stack Overflow用户
提问于 2020-06-16 20:13:30
回答 1查看 2K关注 0票数 2

我正在创建一个票务系统。我需要使用/close命令进行确认。但我该怎么做呢?我试过用if语句,但没有用。这就是我所拥有的:

代码语言:javascript
复制
@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')

我甚至没有发现任何错误?

EN

Stack Overflow用户

发布于 2020-06-16 22:58:11

当等待添加一个反应时,您应该使用"reaction_add"而不是只使用"reaction"

代码语言:javascript
复制
@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

实际上,从这个wait_for返回了两个值,如文档示例 - reactionuser中所示。

此外,discord.Reaction对象没有content属性。

实际上,您需要的是str(reaction)

参考资料:

票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62416842

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档