Discord.net bot,如何创建只有管理员角色才能访问的频道?
Discord.net bot, how to create a channel that only administrator roles have access to?
我想用我的机器人创建一个只有管理员角色才能访问的私人频道。
我已通读 如何让您的机器人创建私人频道特定角色可以 view/join。
截至目前,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 中手动创建频道时那样跳过它。
log reffers to a text channel, Discord.net NuGet package version 2.1.1, Compiling for debug 32-bit with Visual Studio 2019 latest as of now.
为我工作过:
SocketGuild guild = Bot.GetGuild(123456789012345678);
RestTextChannel newChannel = await guild.CreateTextChannelAsync("test-log");
await newChannel.AddPermissionOverwriteAsync(guild.EveryoneRole, OverwritePermissions.DenyAll(newChannel));
事实上,具有管理权限的用户可以访问服务器上的任何频道,我们可以简单地在创建后用DenyAll
覆盖频道权限。
我想用我的机器人创建一个只有管理员角色才能访问的私人频道。
我已通读
截至目前,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 中手动创建频道时那样跳过它。
log reffers to a text channel, Discord.net NuGet package version 2.1.1, Compiling for debug 32-bit with Visual Studio 2019 latest as of now.
为我工作过:
SocketGuild guild = Bot.GetGuild(123456789012345678);
RestTextChannel newChannel = await guild.CreateTextChannelAsync("test-log");
await newChannel.AddPermissionOverwriteAsync(guild.EveryoneRole, OverwritePermissions.DenyAll(newChannel));
事实上,具有管理权限的用户可以访问服务器上的任何频道,我们可以简单地在创建后用DenyAll
覆盖频道权限。