首页 > 解决方案 > 将 .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)});

标签: node.jsdiscord.js

解决方案


你需要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)});

推荐阅读