亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

!創建類別 | 不創建類別 | 該怎么辦?Discord.js

!創建類別 | 不創建類別 | 該怎么辦?Discord.js

波斯汪 2023-06-09 14:56:08
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創建一個包含語音和文本通道的類別。該類別應以您的用戶名命名??刂婆_沒有錯誤,請幫忙,謝謝!
查看完整描述

1 回答

?
慕尼黑的夜晚無繁華

TA貢獻1864條經驗 獲得超6個贊

我不確定是什么導致了您的問題,但請嘗試在創建頻道時設置文本和語音頻道的父級:


// GuildChannelManager#create returns the channel you created

message.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      vvvvv

command(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)

    }

    // ...

})


查看完整回答
反對 回復 2023-06-09
  • 1 回答
  • 0 關注
  • 162 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號