简体   繁体   中英

How can I get id to create voice channel

I am trying to get ID to create a voice channel in discord js v12.

I get an undefined array.

server.channels.create('helicopter', {
                                        type: "VOICE",
                                        parent: id_par
}).then( result => { console.log(result.id); voiceID.push(result.id)})

I also tried:

const newChannel = server.channels.create('helicopter', {
    type: "VOICE",
    parent: id_par
});
let x = await newChannel.id;

Here x is also undefined

And here also:

server.channels.create('sky', {
                                    type: "VOICE",
                                    parent: id_par
        });
id = server.channels.cache.find(channel => channel.name === 'sky' && channel.type === "voice");
voiceID.push(id);

GuildChannelManager#create() returns a Promise meaning we're able to use a .then() function on it and get the channel object directly after the bot finishes completing this method. After getting the channel object, we can simply take its ID and push it into our desired array.

Final Code

guild.channels.create('name here', {
  type: 'voice',
  parent: id_par
}).then(channel => voiceID.push(channel.id))

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