Discord.js创建私人语音频道和角色

时间:2018-05-11 06:41:28

标签: discord.js

我正在尝试使用Discord.js创建一个discord bot,它可以创建一个私有通道和一个新角色,并将该角色分配给该频道。因此,具有新角色的任何用户都可以访问该频道。

以下代码,从我通过' eventName'的名称创建一个频道。它还会创建一个同名角色。

但是,如何将语音通道设为私有,设置角色以专门访问它并为新角色设置一些权限?

function addChannel(message,args,eventName){
var server = message.guild;
var permsName = eventName+"-"+message.author.username;
message.guild.createRole({
    //data: {
        name: permsName,
        permissions: []
    //},
    //reason: 'new Event'
}).then(role => {
    message.member.addRole(role,permsName)
    .catch(error => client.catch(error))
}).catch(error => client.catch(error))
server.createChannel(eventName, 'voice').then( // Create the actual voice channel.
    (chan) => {
        chan.setParent("427382662240534535").then( // Move the voice channel to the current message's parent category.
            (chan2) => {
                console.log("stage 3");
                console.log(chan2);
                //console.log(`Set the category of ${chan2.name} to ${chan2.parent.name}`);
                chan2.overwritePermissions(message.guild.roles.find('name', '@everyone'), { 'CREATE_INSTANT_INVITE' : false }); // Give the channel some standard permissions.
                chan2.overwritePermissions(message.guild.roles.find('name', permsName), {
                    'CREATE_INSTANT_INVITE' : false,        'ADD_REACTIONS': true,
                    'READ_MESSAGES': true,                  'SEND_MESSAGES': true,
                    'SEND_TTS_MESSAGES': true,              'MANAGE_MESSAGES': true,
                    'EMBED_LINKS': true,                    'ATTACH_FILES': true,
                    'READ_MESSAGE_HISTORY': true,           'MENTION_EVERYONE': true,
                    'EXTERNAL_EMOJIS': true,                'CONNECT': true,
                    'SPEAK': true
                  });
                  console.log("stage 4");
            }
        ).catch(console.error);
    }
).catch(console.error);
return '```Added```';

}

0 个答案:

没有答案
相关问题