C# Discord.net bot,如何创建只有管理员角色才能访问的通道?

C# Discord.net bot,如何创建只有管理员角色才能访问的通道?,c#,discord.net,C#,Discord.net,我想用我的机器人创建一个只有管理员角色才能访问的专用通道。 我已经通读了如何让你的机器人创建一个专用的通道,特定角色可以查看/加入 到目前为止,discord有一个功能,您可以完全跳过角色步骤,让所有管理员角色查看它 在discord.net C#中有没有办法做到这一点 以下是我创建频道的代码: var channel = Context.Guild.Channels.SingleOrDefault(x => x.Name == "log"); if (channel

我想用我的机器人创建一个只有管理员角色才能访问的专用通道。 我已经通读了如何让你的机器人创建一个专用的通道,特定角色可以查看/加入

到目前为止,discord有一个功能,您可以完全跳过角色步骤,让所有管理员角色查看它

在discord.net C#中有没有办法做到这一点

以下是我创建频道的代码:

var channel = Context.Guild.Channels.SingleOrDefault(x => x.Name == "log");

if (channel == null) // there is no channel with the name of 'log'
{
     // create the channel
     var newChannel = await Context.Guild.CreateTextChannelAsync("log");

     // If you need the newly created channels id
     var newChannelId = newChannel.Id;
     await ReplyAsync("Created channel ``'log'``");
}
else // reply that the channel already exists
{
     await ReplyAsync("Unable to create channel ``log`` channel already exists.");
}
请记住,这不是重复的,因为另一个问题提到添加可以查看频道的角色,而不是像手动创建不协调频道那样跳过频道

日志引用到一个文本通道Discord.net NuGet包版本2.1.1,使用Visual Studio 2019编译以进行32位调试,目前最新版本

曾为我工作过:

SocketGuild guild = Bot.GetGuild(123456789012345678);
RestTextChannel newChannel = await guild.CreateTextChannelAsync("test-log");
await newChannel.AddPermissionOverwriteAsync(guild.EveryoneRole, OverwritePermissions.DenyAll(newChannel));
事实上,具有管理权限的用户可以访问服务器上的任何频道,我们只需在使用
DenyAll
创建频道后覆盖频道权限即可

SocketGuild guild = Bot.GetGuild(123456789012345678);
RestTextChannel newChannel = await guild.CreateTextChannelAsync("test-log");
await newChannel.AddPermissionOverwriteAsync(guild.EveryoneRole, OverwritePermissions.DenyAll(newChannel));
事实上,具有管理权限的用户可以访问服务器上的任何频道,我们只需在创建后使用
DenyAll
覆盖频道权限即可