删除反应频道//Ticket Bot discord.py



我正在尝试制作一个票证机器人,这就是我目前所拥有的。现在我可以让机器人在检测到反应后创建一个通道,我需要能够让它关闭另一个反应的票证,以及要添加的其他功能。但是这个反应是在创建的通道中,所以我不知道如何创建通道id。有人建议我使用齿轮,但不知道从哪里开始。

async def on_raw_reaction_add(payload):
channel = payload.channel_id
if channel == 862711339298455563:
guildid = payload.guild_id
guild = client.get_guild(guildid)
channel = guild.get_channel(payload.channel_id)
message = channel.get_partial_message(payload.message_id)
emoji = '🎟️'
member = payload.member

payloaduserid = payload.user_id
clientuserid = client.user.id   
if payloaduserid != clientuserid: 
await message.remove_reaction(emoji, member)
category = client.get_channel(861003967000215583)
channel1 = await guild.create_text_channel(f'ticket {payload.user_id}', category = category )
ticketembed = discord.Embed(
title = f'Ticket - {payload.user_id}',
description = '- If you want to tag the admins please react with :telephone: n - To report this message please react with   :warning: n - To close the ticket react this mesaage with   :x:  ',
color = discord.Color.red())
ticketembed.set_footer(text = 'All of the conversation will be held in the archives, eventhought a moderator can delete a message in this channel, a copy of it will be held in a location where only the owner can access.')

user = client.get_user(payload.user_id)
await channel1.set_permissions(target=user, read_messages=True , send_messages=True)

ticketembed1 = await channel1.send(embed= ticketembed)
await ticketembed1.add_reaction('☎️')
await ticketembed1.add_reaction('⚠️')
await ticketembed1.add_reaction('❌') 
await channel1.send(f'{user.mention}', delete_after = 0.1) ```

一种方法是检查通道名称格式。有时从缓存中获取通道不是一个选项,所以我们可能需要获取它。

async def on_raw_reaction_add(payload):
channel = client.get_channel(payload.channel_id)
# if channel is not in cache then fetch is using a API request
if not channel:
channel = await client.fetch_channel(channel_id)
# The user is the owner of the ticket since it is his id
if channel.name == f"ticket {payload.user_id}":
emoji = payload.emoji.name
# delete 
if emoji == "❌":
await channel.delete()

最好先保存频道id,然后再使用它,因为频道名称可以更改。你可以这样得到身份证。

channel1 = await guild.create_text_channel(f'ticket {payload.user_id}', category = category )
print(channel1.id)