【问题标题】:How to make discord close a ticket channel?如何让discord关闭售票渠道?
【发布时间】:2021-09-21 18:36:12
【问题描述】:
@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, send_messages=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”对象没有属性“删除”

非常感谢您的帮助,因为它已经很长时间了,我找不到解决方案,一切都好

【问题讨论】:

    标签: python arrays python-3.x discord discord.py


    【解决方案1】:

    创建时您使用的频道名称不正确。

    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}")
    

    另外一个建议使用author.id,因为它不能像名字一样被改变

    【讨论】:

    • AttributeError: 'str' 对象没有属性 'id'
    • 我没有在我的代码中使用id 那么你到底指的是什么?如果你的意思是作者,那么它应该是 ctx.author.id 并确保它是一个成员对象打印它的类型。
    • 没有兄弟,就像有人说 *ticket 它会创建票证并将制作票证的成员添加到票务支持角色到频道权限中,所以我想当我说 *close 时删除票证频道
    • 它工作 OMG YAY 是的,我现在使用作者 ID,非常感谢兄弟
    猜你喜欢
    • 2020-12-27
    • 2021-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-12
    • 1970-01-01
    相关资源
    最近更新 更多