删除频道反应 |不和谐.py

时间:2021-07-01 08:50:33

标签: python discord discord.py

我正在为我的服务器创建票证工具。因此,每当用户对消息做出反应时,都会创建一个新频道,但我希望机器人在该新频道中发送一条消息,说“在下面做出反应以删除票证。”。但是我可以在不将 msg_id 和其他数据存储在全局变量中的情况下做到这一点吗?

代码:

@bot.event
async def on_raw_reaction_add(payload):
    if payload.member.id != bot.user.id and str(payload.emoji)== u"\U0001F3AB":
        msg_id, channel_id, category_id= bot.ticket_configs[payload.guild_id]

        if payload.message_id == msg_id:
            guild= bot.get_guild(payload.guild_id)

            for category in guild.categories:
                if category.id == category_id:
                    break
                    
            guild = await bot.fetch_guild(460654239094669332)
            channels = guild.text_channels
            channel = guild.get_channel(842807548968042536)
            
            duplicate = False
            topic = f"<@!{payload.member.id}>'s ticket"
            for channel in channels:
              if topic == channels.topic:
                duplicate = True
                break
                
            if duplicate:
              return
            

            else:
              ticket_num= 1 if len(category.channels) == 0 else int(category.channels[-1].name.split("-")[1]) + 1

              ticket_channel= await category.create_text_channel(f"Ticket-{ticket_num}", topic= topic, permission_synced= True)
            await ticket_channel.set_permissions(payload.member, read_messages= True, send_messages= True) 
              print(msg_id)
              
              
              embed=  discord.Embed(title= "New Ticket!!!", description= f"{payload.member.mention} Thank You! for creating this ticket staff will contact you soon. Type **-close** to close the ticket.")
              message= await ticket_channel.send(embed=embed)
              await message.add_reaction("❌")

非常感谢您的帮助

1 个答案:

答案 0 :(得分:0)

您可以通过简单的检查使用 bot.wait_for

message = await ctx.send("React below to delete the ticket")

def check(reaction, user):
    return reaction.message == message and str(reaction) == "✅"  # you can use another emoji, or don't use it at all

try:
    await bot.wait_for("reaction_add", check=check, timeout=60.0)  # timeout is optional
except asyncio.TimeoutError:
    ...
else:
    await channel.delete()  # where `channel` is the channel to delete