为什么我的不和谐角色返回未定义?

时间:2020-09-03 17:43:05

标签: javascript discord.js

好吧,所以我有一些创建角色的基本代码,并且找到了角色,我尝试从保存或找到它的const中获取const的ID,但是在100%的时间中它为空,因此创建了角色并IDK问题。

const roleowo = msg.guild.createRole({ name: channelname, color: 'YELLOW' }).then((role) => {msg.member.addRole(role);}).catch(console.error);
                let myRole = msg.guild.roles.get(roleowo);

                msg.guild.createChannel(channelname, {
                type: 'voice',
                permissionOverwrites: [
                  {
                    id: 'this is an actual id but I will not show it here I am dumb',
                    deny: ['VIEW_CHANNEL'],
                  },
                    {
                      id: myRole.id,
                      allow: ['VIEW_CHANNEL'],
                    }
                  ]
                });

1 个答案:

答案 0 :(得分:2)

roleowo等于Promise<Role>。您需要将所有代码放入.then()

msg.guild.createRole({ name: channelname, color: 'YELLOW' })
    .then((role) => {
        msg.member.addRole(role);
        
        msg.guild.createChannel(channelname, {
            type: 'voice',
            permissionOverwrites: [
                {
                    id: 'this is an actual id but I will not show it here I am dumb',
                    deny: ['VIEW_CHANNEL'],
                },
                {
                    id: role.id,
                    allow: ['VIEW_CHANNEL'],
                }
            ]
        });
    })
    .catch(console.error);