只删除一个频道 - Discord.py

时间:2021-02-26 01:18:59

标签: python discord.py

我做了这个命令来删除一个以Ticket开头的频道(例如),但它删除了所有以这个词开头的频道,有没有办法让它只删除它被调用的频道?

我的代码(在一个齿轮中):

@commands.command()

async def close(self, ctx):
    for channel in ctx.guild.text_channels:
        if channel.name.startswith(("ticket","recrutement","partenariat","tickets","partenariats")):
            await chat_exporter.quick_export(ctx)
            await asyncio.sleep(10)
            await channel.send("Suppression...")
            await asyncio.sleep(5)
            await channel.delete()

先谢谢你!

1 个答案:

答案 0 :(得分:0)

就在这里的这一行:if channel.name.startswith(("ticket","recrutement","partenariat","tickets","partenariats")):,您是说如果频道名称 startswith(内置字符串函数)中的任何一个值,则执行操作。如果您希望它更具体,请使用 in 来精确匹配:if channel.name in ("ticket","recrutement","partenariat","tickets","partenariats"): 现在它不仅检查每个频道名称的首字母是否匹配,还检查整个频道名称。这应该可以解决您描述的问题。