diff --git a/api/src/routes/guilds/index.ts b/api/src/routes/guilds/index.ts
index abde147d..6a325ae2 100644
--- a/api/src/routes/guilds/index.ts
+++ b/api/src/routes/guilds/index.ts
@@ -87,19 +87,21 @@ router.post("/", route({ body: "GuildCreateSchema" }), async (req: Request, res:
});
await Promise.all(
- body.channels?.map((x) => {
- var id = ids.get(x.id) || Snowflake.generate();
-
- // TODO: should we abort if parent_id is a category? (to disallow sub category channels)
- var parent_id = ids.get(x.parent_id);
-
- return Channel.createChannel({ ...x, guild_id, id, parent_id }, req.user_id, {
- keepId: true,
- skipExistsCheck: true,
- skipPermissionCheck: true,
- skipEventEmit: true
- });
- })
+ body.channels
+ ?.sort((a, b) => (a.parent_id ? -1 : 1))
+ .map((x) => {
+ var id = ids.get(x.id) || Snowflake.generate();
+
+ // TODO: should we abort if parent_id is a category? (to disallow sub category channels)
+ var parent_id = ids.get(x.parent_id);
+
+ return Channel.createChannel({ ...x, guild_id, id, parent_id }, req.user_id, {
+ keepId: true,
+ skipExistsCheck: true,
+ skipPermissionCheck: true,
+ skipEventEmit: true
+ });
+ })
);
await Member.addToGuild(req.user_id, guild_id);
|