!创建类别 | 不创建类别 | 该怎么办?Discord.js

client.on('ready', () => {

    command(client, 'createcategory', (message) => {

      const name = message.content.replace('!createcategory ', '')

      

      if(message.guild.channels.cache.find(c => c.name == message.author.username && c.type == "category") === undefined){

          message.guild.channels.create(message.author.username, {type: 'category', permissionOverwrites: [

          {

              id: message.guild.id,

              deny: ['VIEW_CHANNEL'],

          },

          {

              id: message.author.id,

              allow: ['VIEW_CHANNEL'],

          },

      ]})

      message.guild.channels.create('Text channel', {type: 'text', permissionOverwrites: [

        {

            id: message.guild.id,

            deny: ['VIEW_CHANNEL'],

        },

        {

            id: message.author.id,

            allow: ['VIEW_CHANNEL'],

        },

    ]}).then(channel => {

      let category = message.guild.channels.cache.find(c => c.name == message.author.username && c.type ==       "category");

  

      if (!category) throw new Error("Category channel does not exist");

      channel.setParent(category.id);

    }).catch(console.error);

      message.guild.channels.create('Voice channel', {type: 'voice', permissionOverwrites: [

        {

            id: message.guild.id,

            deny: ['VIEW_CHANNEL'],

        },

        {

            id: message.author.id,

            allow: ['VIEW_CHANNEL'],

        },

    ]}).then(channel => {

      let category = message.guild.channels.cache.find(c => c.name == message.author.username && c.type ==       "category");

  

      if (!category) throw new Error("Category channel does not exist");

      channel.setParent(category.id);

    }).catch(console.error);

       } else {message.send('Jau tu turi kanala, kurviuk tu')}

  });

});

代码曾经有效,但不知何故我忘记了我用它做了什么并且没有编码 2 个月左右......功能应该是 - 当你编写它时应该!createcategory创建一个包含语音和文本通道的类别。该类别应以您的用户名命名。控制台没有错误,请帮忙,谢谢!


波斯汪
浏览 131回答 1
1回答

慕尼黑的夜晚无繁华

我不确定是什么导致了您的问题,但请尝试在创建频道时设置文本和语音频道的父级:// GuildChannelManager#create returns the channel you createdmessage.guild.channels.create(message.author.username, {    type: 'category',    permissionOverwrites: [        {id: message.guild.id, deny: ['VIEW_CHANNEL']},        {id: message.author.id, allow: ['VIEW_CHANNEL']},    ]}).then(parent => {    // Create the text channel    message.guild.channels.create('Text channel', {        type: 'text',        // under the parent category        parent, // shorthand for parent: parent        permissionOverwrites: [            {id: message.guild.id, deny: ['VIEW_CHANNEL']},            {id: message.author.id, allow: ['VIEW_CHANNEL']},        ]    }).catch(console.error)    // Same with the voice channel    message.guild.channels.create('Voice channel', {        type: 'voice',        parent,        permissionOverwrites: [            {id: message.guild.id, deny: ['VIEW_CHANNEL']},            {id: message.author.id, allow: ['VIEW_CHANNEL']},        ]    }).catch(console.error)})你也可以使用 ES2017 的async/await:// Must be an async function      vvvvvcommand(client, 'createcategory', async (message) => {   // ...   const parent = await message.guild.channels.create(/* ... */)    try {        // Run the promises concurrently, like in your code        await Promise.all([            message.guild.channels.create('Text channel', {/* ... */})            message.guild.channels.create('Voice channel', {/* ... */)        ])    } catch (error) {        console.error(error)    }    // ...})
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript