简体   繁体   中英

Create a channel in specific category discord.js

How can I create a channel in specific category? I tried this:

reaction.message.guild.channels.create(`ticket-${user.name}`).setParent(config.ticket_categorie)

But it created the channel at the top without any category.

You can create a channel, and then assign it to x category like this:

reaction.message.guild.channels.create("CHANNEL_NAME")
  .then(channel => {
    channel.setParent("CATEGORY_ID");
  })
  .catch(err => {
    console.log(err)
  });

I guess that if you use a .then in create and used setParent on the return of the create function (which is the channel) the category would be applied. This question mentions this, as well as a way of using it with the 12th version of the lib. Also you should use the category id at setParent, it seems you're using the name of the category, which could be the problem.

add channel to category

And according to this other link, you could use the parent option passed as the second parameter to the create function to provide a category id that the channel belongs: Use parent option with create

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM