permissions - 从 TextChannel 获取权限 - Discord.js
问题描述
基本上,我需要从用户所在的当前文本频道中获取权限。我已经获得了频道名称,如果我需要获取应该很容易做到的 ID。
const Discord = require("discord.js");
module.exports.run = async (client, message, args) => {
let currentChannel = message.channel.name;
let category = message.channel.parent;;
message.guild.createChannel(currentChannel).then(mchannel => {
mchannel.setParent(category).then(() => {
message.channel.delete();
});
});
}
module.exports.help = {
name: "a.cleanchannel"
}
// Need the channel permissions to overwrite the new channel's permissions with the old ones
预期的结果是该通道应该具有与旧通道相同的权限。
解决方案
要直接回答您的问题,您可以使用GuildChannel#permissionOverwrites
创建具有与旧频道相同权限的新频道。例如...
message.guild.createChannel(message.channel.name, {
type: 'text',
permissionOverwrites: message.channel.permissionOverwrites
});
但是,您似乎正在尝试克隆频道。为了让这更容易,Discord.js 中内置了一个方法 - GuildChannel#clone()
. 你可以像这样使用它...
message.channel.clone(undefined, true, true) // Same name, same permissions, same topic
.then(async clone => {
await clone.setParent(message.channel.parent);
await clone.setPosition(message.channel.position);
await message.channel.delete();
console.log(`Cloned #${message.channel.name}`);
})
.catch(console.error);
推荐阅读
- powershell - Powershell 重命名文件
- javascript - Javascript 和 css 语法,如何定义 'px'
- javascript - 在 Day.js 减少倒数计时器的秒数时出现问题(尝试从 moment.js 迁移)
- html - 如何使链接打开 html 文件而不是同页锚?
- reactjs - ReactNative 应用程序使用什么数据库?
- sql - 在 SQL Server 向导中导入期间导入停止复制到表
- angularjs - 无法使用 Neovis.js 从 Neo4j 以角度呈现图形
- forms - 复制粘贴信息路径重复表行将数字字段重置为零
- javascript - 在 gatsby-node.js 构建期间获取数据并在运行时检索数据并通过 graqhql 呈现
- c# - C#插入Access数据库不工作并且没有异常或错误