javascript - 保存新创建的角色和频道的 ID
问题描述
我正在尝试保存我刚刚创建的频道和角色的 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)
返回未定义,即使我已将其设置为chan.id
.
解决方案
我不完全确定,但你的问题可能是你在控制台日志之后声明了 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);
推荐阅读
- javascript - 为什么 Chrome 没有显示我的 User Timing API 使用情况的任何数据?
- spring - 在 Spring cloud consul config 中监听上下文刷新
- ruby - 正则表达式匹配不同于第一个字符的字符
- python - 为什么python中的某些包或函数的首字母大写,而有些则不是?
- reactjs - 在无状态功能组件中使用 Ref 在 React JS 中不起作用
- css - 图像背景而不是下拉按钮
- android - 两个或多个带有进度的前台通知在更新进度时相互替换
- python - 使用 itemcget 在 tkinter 中获取单个列表框项属性?
- android - 固定状态栏和隐藏导航栏
- reactjs - 在 React 上使用段并调用“analytics.default.track”错误“超出最大调用堆栈大小”