【问题标题】:Discord.net bot, how to create a channel that only administrator roles have access to?Discord.net bot,如何创建只有管理员角色才能访问的频道?
【发布时间】:2021-08-18 20:38:21
【问题描述】:

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

到目前为止,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 位进行编译。

【问题讨论】:

    标签: c# discord.net


    【解决方案1】:

    为我工作过:

    SocketGuild guild = Bot.GetGuild(123456789012345678);
    RestTextChannel newChannel = await guild.CreateTextChannelAsync("test-log");
    await newChannel.AddPermissionOverwriteAsync(guild.EveryoneRole, OverwritePermissions.DenyAll(newChannel));
    

    事实上,拥有Administrator权限的用户可以访问服务器上的任何频道,我们可以简单地在创建后用DenyAll覆盖频道权限。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-15
      • 1970-01-01
      • 1970-01-01
      • 2015-05-17
      • 2015-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多