繁体   English   中英

如何获取 id 来创建语音通道

[英]How can I get id to create voice channel

我正在尝试获取 ID 以在 discord js v12 中创建语音通道。

我得到一个未定义的数组。

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

我也试过:

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

这里x也是未定义

这里还有:

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()返回一个Promise意味着我们可以在其上使用 .then .then() function 并在机器人完成此方法后直接获取频道 object。 获得通道 object 后,我们可以简单地获取它的 ID 并将其推送到我们想要的数组中。

最终代码

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM