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)
}
// ...
})
添加回答
舉報