我正在尝试保存刚刚创建的频道和角色的ID,以便以后继续删除它们。我试图将ID存储在变量中,以便以后可以从单独的文件中公开访问它们。这就是我要尝试的方式:
let categoryID;
let channelID;
Promise.all([r1, c1, c2]).then(([role, cat, chan]) => {
chan.setParent(cat);
chan.overwritePermissions([
{
//everyone
id: '762492106156539945',
deny: ['SEND_MESSAGES', 'VIEW_CHANNEL']
},
{
//verified
id: '763048301552992346',
allow: ['VIEW_CHANNEL']
},
{
//new role
id: role.id,
allow: ['SEND_MESSAGES']
}
])
console.log(chan.id);
console.log(cat.id);
channelID = chan.id;
categoryID = cat.id;
});
console.log(categoryID);
console.log(channelID);
console.log(chan.id)
有效,但是console.log(channelID)
返回undefined,即使我将其设置为chan.id
。
答案 0 :(得分:0)
我不确定,但是如果您得到我想说的话,您的问题可能是您在控制台日志后声明了channelID变量。尝试以下代码:
let categoryID;
let channelID;
Promise.all([r1, c1, c2]).then(([role, cat, chan]) => {
chan.setParent(cat);
chan.overwritePermissions([
{
//everyone
id: '762492106156539945',
deny: ['SEND_MESSAGES', 'VIEW_CHANNEL']
},
{
//verified
id: '763048301552992346',
allow: ['VIEW_CHANNEL']
},
{
//new role
id: role.id,
allow: ['SEND_MESSAGES']
}
])
channelID = chan.id;
categoryID = cat.id;
console.log(chan.id);
console.log(cat.id);
});
console.log(categoryID);
console.log(channelID);