我正在尝试使用 Discord.js 制作一个不和谐机器人,它可以创建一个私人频道和一个新角色,并将该角色分配给该频道。因此,任何具有新角色的用户都可以访问该频道。
以下代码根据我通过“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```';
Run Code Online (Sandbox Code Playgroud)
}
小智 6
这里有两个问题,一个是你在这里使用了很多不必要的权限,对于 Voice 显然反应阅读和发送消息等并不重要,重要的只有 VIEW_CHANNEL、SPEAK、CONNECT 和 CREATE_INSTANT_INVITE,你必须明确禁止所有人标准的不和谐服务器设置,因为除非在本地覆盖,否则每个人通常都在服务器范围内拥有这些权限。
所以你想要的覆盖权限是:
chan2.overwritePermissions(message.guild.roles.find('name', '@everyone'), { // Disallow Everyone to see, join, invite, or speak
'CREATE_INSTANT_INVITE' : false, 'VIEW_CHANNEL': false,
'CONNECT': false, 'SPEAK': false
});
chan2.overwritePermissions(message.guild.roles.find('name', permsName), {//Explicitely allow the role to see, join and speak
'VIEW_CHANNEL': true, 'CONNECT': true, 'SPEAK': true,
});
Run Code Online (Sandbox Code Playgroud)
请注意,您不必明确禁止 CREATE_INSTANT_INVITE,因为如果没有明确更改,它会从每个人那里继承。
| 归档时间: |
|
| 查看次数: |
14180 次 |
| 最近记录: |