我现在正在用 python 制作一个 discord bot,并想添加一个功能来删除公会中频道名称列表中的所有频道。我尝试浏览存储在“ctx.message.guild.channel”列表中的所有频道,并检查它们是否在我的频道名称列表中,但它没有找到频道,所以什么也没有发生。谢谢你已经帮了我!
channel_names = ["channel1","channel2","channel3"]
@commands.command()
async def clear(self, ctx):
for channel in list(ctx.message.guild.channel):
if channel in channel_names:
await channel.delete()
答案 0 :(得分:0)
要获取文本频道,您必须使用 text_channels 和 text_channel.name 进行比较。
channel_names = ["channel1","channel2","channel3"]
@commands.command()
async def clear(self, ctx):
for channel in list(ctx.message.guild.text_channels):
if channel.name in channel_names:
await channel.delete()