var server = message.guild;
for (var i = 0; i < server.channels.array().length; i++) {
server.channels.array()[i].delete();
}
server.createChannel("Text Channels", "category");
server.createChannel('general', "text");
我正在尝试使文本通道“常规”进入“文本通道”类别
所有解决方案,我发现依赖于您知道类别ID 。我想知道是否有办法我可以获取类别ID ,或者仅通过其名称将通用名称移入“文本通道”。
注意::目前,我正在考虑按照以下方式获取类别ID:
var categoryID = server.categories.find("name","Text Channels");
然后使用
server.channels.find("name","general").setParent(categoryID);
答案 0 :(得分:1)
您可以使用GuildChannel.setParent()
。请记住,Discord将类别视为渠道:CategoryChannel
扩展了GuildChannel
,因此您可以使用GuildChannel.type
要分配现有频道,请执行以下操作:
let category = server.channels.find(c => c.name == "Text Channels" && c.type == "category"),
channel = server.channels.find(c => c.name == "general" && c.type == "text");
if (category && channel) channel.setParent(category.id);
else console.error(`One of the channels is missing:\nCategory: ${!!category}\nChannel: ${!!channel}`);
要创建新频道:
server.createChannel("general", "text")
.then(channel => {
let category = server.channels.find(c => c.name == "Text Channels" && c.type == "category");
if (!category) throw new Error("Category channel does not exist");
channel.setParent(category.id);
}).catch(console.error);