【问题标题】:Discord doesn't delete channelDiscord 不会删除频道
【发布时间】:2021-09-21 03:01:53
【问题描述】:
@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”对象没有属性“删除”

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

【问题讨论】:

  • 那个错误意味着foundchan是空的,我在文档中寻找guild.text_channels api,你在哪里找到的,你能链接一些源代码吗?
  • 我自己做的
  • 我怀疑那是问题所在。您是否也可以在问题中添加该部分。
  • 你是不是有什么不和或者我在这里不能说太久的事情
  • stackoverflow.com/questions/59523537/… 这可能会有所帮助

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


【解决方案1】:

https://stackoverflow.com/a/64282450/7116645

参考上述答案并为您的代码修改它。 你可以试试下面的代码:

@client.command()
async def close(ctx):
    foundchan = discord.utils.get(
        ctx.guild.channels, name=f"ticket-{ctx.author.name}")
    # await discord.Member.send(f"Your ticket was closed by {ctx.author.name}")
    if foundchan is not None:
        await foundchan.delete()
    else:
        print("No channel exist by that Name")

还有其他版本可以试试

@client.command()
async def close(ctx):
    foundchan = discord.utils.get(
        ctx.all_channels(), guild__name=ctx.guild, name=f"ticket-{ctx.author.name}")
    # await discord.Member.send(f"Your ticket was closed by {ctx.author.name}")
    if foundchan is not None:
        await foundchan.delete()
    else:
        print("No such channel")

当然,还要确保该频道存在!

【讨论】:

  • AttributeError: 'Context' 对象没有属性 'all_channels'
  • 一直打印没有这样的频道
猜你喜欢
  • 2020-12-06
  • 1970-01-01
  • 2020-04-18
  • 2020-10-01
  • 2021-08-28
  • 2021-01-12
  • 2021-05-14
  • 2020-09-11
  • 2020-12-04
相关资源
最近更新 更多