在不和谐的情况下创建类别,其权限只有特定角色才能加入并键入

时间:2020-09-20 02:57:10

标签: python discord.py discord.py-rewrite

希望使仅具有特定角色(在同一命令中)可见的带有文本和语音通道的类别...这是到目前为止的内容,但是在向其中添加权限时我有点迷失类别。

@bot.command(pass_context=True)
@commands.has_permissions(kick_members=True)
async def createfriendgroup(ctx, role_name):
    guild = ctx.guild
    await guild.create_category(role_name)
    category = discord.utils.get(ctx.guild.categories, name = role_name)
    await guild.create_role(name = role_name)
    await guild.create_text_channel(f"{role_name}-private-tc", category = category, sync_permissions=True)
    await guild.create_voice_channel(f"{role_name}-private-vc", category = category, sync_permissions=True)

因此,我已经创建了类别,文本和语音通道(都具有同步的权限),但是现在知道如何在类别内设置权限,因此任何帮助都将非常惊人!谢谢!

1 个答案:

答案 0 :(得分:0)

您有2个选项,可以执行CategoryChannel.set_permissionsCategoryChannel.edit

  1. set_permissions()
@bot.command()
@commands.has_permissions(kick_members=True)
async def createfriendgroup(ctx, role_name):
    guild = ctx.guild
    category = await guild.create_category(role_name)
    role = await guild.create_role(name = role_name)
    await category.set_permissions(role, read_messages=True, send_messages=True, connect=True, speak=True)
    await category.set_permissions(ctx.guild.default_role, read_messages=False, connect=False)
    await guild.create_text_channel(f"{role_name}-private-tc", category = category, sync_permissions=True)
    await guild.create_voice_channel(f"{role_name}-private-vc", category = category, sync_permissions=True)
  1. 使用覆盖
@bot.command()
@commands.has_permissions(kick_members=True)
async def createfriendgroup(ctx, role_name):
    guild = ctx.guild
    category = await guild.create_category(role_name)
    role = await guild.create_role(name = role_name)
    overwrites = {
                    ctx.guild.default_role: discord.PermissionOverwrite(read_messages=False, connect=False),
                    role: discord.PermissionOverwrite(read_messages=True, send_messages=True, connect=True, speak=True)
                  }
    await category.edit(overwrites=overwrites)
    await guild.create_text_channel(f"{role_name}-private-tc", category = category, sync_permissions=True)
    await guild.create_voice_channel(f"{role_name}-private-vc", category = category, sync_permissions=True)