guild.channels.create
returns a promise so you either need to use the .then()
method or async-await to get randomCategory
. At the moment it's just a pending promise, not the returned category:
// make the function an async function
async function createChannel() {
randomString = crypto.randomBytes(12).toString('hex');
// use await to wait the promise to resolve
const randomCategory = await message.guild.channels.create(randomString, {
type: 'category',
permissionOverwrites: [
{
id: message.guild.id,
allow: ['VIEW_CHANNEL'],
},
],
});
message.guild.channels.create(randomString, {
type: 'text',
// pass the randomCategory object, not just the id
parent: randomCategory,
permissionOverwrites: [
{
id: message.guild.id,
allow: ['VIEW_CHANNEL'],
},
],
});
message.guild.channels.create(randomString, {
type: 'voice',
// pass the randomCategory object, not just the id
parent: randomCategory,
permissionOverwrites: [
{
id: message.guild.id,
allow: ['VIEW_CHANNEL'],
},
],
});
}
It seems to be working fine:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…