如何通过id获取类别?

问题描述 投票:0回答:3

我正在制作一个创建频道的机器人。他必须在某个类别中创建频道。我正在使用

guild.create_text_channel()
。我在文档中没有找到执行此操作的方法。欢迎任何帮助。

python-3.x discord.py
3个回答
5
投票

您可以使用

discord.utils.get
通过 id 获取类别。这是它的用法:

guild = discord.utils.get(client.guild.categories, id='put the id here without apostrophes')

4
投票

你可以用这个来做到。

from discord.utils import get

category = get(guild.category_channels, name="CATEGORY_NAME")
await guild.create_text_channel("CHANNEL_NAME", category=category)

0
投票

在 2024 年,如果您在获取某个类别中的频道时遇到问题,您可以通过执行此操作来获取该类别

category = discord.utils.get(bot.guilds[0].categories, id=CATEGORY_ID)

© www.soinside.com 2019 - 2024. All rights reserved.