如何在discord.py中获取当前类别的名称



我需要一些关于我的机器人的帮助,由discord.py编写。我在一个机器人中有一个异步函数,它通过从一个带有通道的命令和必须删除通道的函数中获取名称来创建一个类别。此外,此函数必须仅删除调用的当前通道。例如:我有三类频道。例如1、2、3。例如,我在2中替换的通道中调用了命令delete。此命令将删除此具有类别的频道,并且不会触及其他类别。我怎么需要wtite这个过程。我想按职位获得类别的当前名称,但我知道这不会奏效。给我一些建议或想法,如何做到这一点。

部分代码:

导入不和从discord.ext导入命令

@bot.command()
async def NewChannel(ctx, name):
guild = ctx.message.guild
await guild.create_category(name=name)
cat = discord.utils.get(ctx.guild.categories, name=name)
text_channel = await guild.create_text_channel(name="text", category=cat)

@bot.command()
async def delete_current_channel(ctx):
guild = ctx.guild #How to get current category in which will send this command?
channel = discord.utils.get(guild.text_channels, name="current_category")
await channel.delete()

在这方面我是绿色的初级。很抱歉我的信息中有错误,请帮帮我。我没有什么想法。

我不确定你在这里到底想做什么,但你可以通过channel.category获得频道类别

类别名称:channel.category.name

https://discordpy.readthedocs.io/en/master/api.html?highlight=channel%20category#discord.abc.GuildChannel.category

最新更新