Whenever someone submits an application for the server, a designated channel is created at the top of the server (view example here). However, responding to these applications in a consistent order has proven challenging due to various factors. Once I respond to an application, the channel is closed and moved to a category called "Past Channels" (see example here). The issue arises when trying to order the channels within the category based on the application number rather than placing them at the top.
I have attempted the following method, but it has not yielded the desired outcome. It is important to note that I am coding in TypeScript.
function setPosition(client: myClient, channel: TextChannel) {
const regex = /\d{4}$/;
const appnum = Number(regex.exec(channel.name)![0]);
console.log(`[SLASH COMMANDS] Application #${appnum} has been processed.`);
const category = client.channels.cache.get(client.categoryPastApplications);
if (!category || category.type !== ChannelType.GuildCategory) {
console.log(
`[SLASH COMMANDS] An error occurred while executing the "application" command! Error #6`
);
return;
}
const channelsCategory = category.children.cache.sort((a, b) => a.position - b.position);
channelsCategory.forEach((categoryChannel) => {
if (Number(regex.exec(categoryChannel.name)![0]) > appnum) {
channel.setPosition(categoryChannel.position + 1);
}
});
}
Update: I attempted a different approach with the function as shown below, but the issue persists.
async function setPosition(client: myClient, channel: TextChannel) {
const regex = /\d{4}$/;
const appnum = Number(regex.exec(channel.name)![0]);
console.log(`[SLASH COMMANDS] Application #${appnum} has been processed.`);
const category = client.channels.cache.get(client.categoryPastApplications);
if (!category || category.type !== ChannelType.GuildCategory) {
console.log(
`[SLASH COMMANDS] An error occurred while executing the "application" command! Error #6`
);
return;
}
const channelsCategory = category.children.cache.sort((a, b) => a.position - b.position);
Object.values(channelsCategory).forEach(async (categoryChannel, index) => {
if (Number(regex.exec(categoryChannel.name)![0]) < appnum) {
await channel.setPosition(index + 1);
}
});
}