node.js - 将 .then(value) 中的值设置为以后可以使用的全局值
问题描述
我如何.then
在第二个语句中使用第一个语句中的值?我想在第二个.then
和第三个中使用 d_channel
message.guild.channels.create('register-'+username[0], {
type: 'text',
permissionOverwrites: [{
id: message.member.user.id,
allow: ['VIEW_CHANNEL'],
},
{
id: "707236888330895380",
deny: ['VIEW_CHANNEL'],
}],
}).then((d_channel) =>{
const categoryId = '732596048324984863';
d_channel.setParent(categoryId);
//channel.delete(100000);
console.log(d_channel.id)
}).then(()=>{ console.log(d_channel.id)});
解决方案
你需要d_channel
在承诺链中不断传递。
}).then((d_channel) =>{
const categoryId = '732596048324984863';
d_channel.setParent(categoryId);
//channel.delete(100000);
console.log(d_channel.id)
return d_channel // pass it to the next promise in the chain
}).then((d_channel)=>{ console.log(d_channel.id)});
推荐阅读
- .net - 数千个后台作业的可扩展解决方案,每个作业都打开 Web 套接字
- azure - Azure 数据工厂:摄取 - 从 Delta 表到 Postgres
- c# - CSharp:无法读取 LARGE .npy 文件。例外是“NumSharp.dll 算术运算导致溢出”。
- python - 来自 gdf 的 Osmnx 基本统计数据
- go - 如何在 nix-shell 中安装带有自定义标签的 golang 包?
- java - -1+ (int) 是什么意思?
- filter - 分组后如何按父值过滤结果?
- javascript - 通过页面上的某个点后隐藏 div 的 JavaScript
- javascript - 无法分配类型的值(又名“数组”
>') 到 (又名'字典 ') - blazor - 将 Blazor .NET 6 WASM 部署到 GitHub 页面