如何使不和谐关闭票务通道?

问题描述

@client.command()
async def ticket(ctx):
    #new_channel = discord.utils.get(ctx.guild.text_channels,name=f"ticket-{message.author.name}")
    name = 'TICKETS'
    category = discord.utils.get(ctx.guild.categories,name=name)
    foundchan = discord.utils.get(
        ctx.guild.text_channels,name=f"Ticket-{ctx.author.name}")
    if category is None:
        await ctx.guild.create_category(name)

    if foundchan is None:
        channel = await ctx.guild.create_text_channel(f'Ticket-{ctx.author.name}',category=category)
    if foundchan:
        await ctx.channel.send("ALREADY A  CHANNEL")
    Role = discord.utils.get(ctx.guild.roles,name="Ticket Support")
    if Role is None:
        await ctx.guild.create_role(name="Ticket Support")
    else:
        await channel.set_permissions(ctx.author,read_messages=True,send_messages=True,view_channel=True)
        await channel.set_permissions(ctx.guild.default_role,view_channel=False)
        await channel.set_permissions(Role,view_channel=True,add_reactions=True)
        await channel.send(f"hey,{ctx.author.mention},thank you for creating a ticket; please be patient untill one of our staff member to come.")
        await channel.send("**Say '*close' to close the ticket.**")


@client.command()
async def close(ctx):
    foundchan = discord.utils.get(
        ctx.guild.text_channels,name=f"ticket-{ctx.author.name}")
    # await discord.Member.send(f"Your ticket was closed by {ctx.author.name}")
    await foundchan.delete()
#Here is the full code everything is working but when i try to delete the channel it doesnt work and give me this error  'nonetype' object has no attribute 'delete'

我需要帮助它给了我这个错误nonetype”对象没有属性删除

真的很感谢您的帮助,因为它已经很长时间了,我无法找到解决方案,一切皆有可能

解决方法

您没有获得正确的频道名称,创建时您正在使用它。

MY_FILE_NAME_H

您使用带有大写 channel = await ctx.guild.create_text_channel(f'Ticket-{ctx.author.name}',category=category) Ticket 但在获取频道时您使用了 T

ticket

另一个建议使用 foundchan = discord.utils.get(ctx.guild.text_channels,name=f"ticket-{ctx.author.name}") ,因为它与名称不同,无法更改