在response//Ticket Bot discord.py上删除频道

2024-10-03 09:17:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试制作一个票务机器人,这就是我目前拥有的。现在,我可以让机器人在检测到一个反应后创建一个通道,我需要能够让它关闭另一个反应的记录单,以及我想添加的其他功能。但是这个反应在创建的通道中,所以我不知道如何创建通道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) ```

Tags: theclientaddidmessagegetchannelawait
1条回答
网友
1楼 · 发布于 2024-10-03 09:17:27

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

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)

相关问题 更多 >