首页 > 解决方案 > 如何设置用户特定的频道权限 discord.py

问题描述

我正在尝试创建一个支持系统,用户可以在其中发言;support reason,然后使用权限创建一个频道,供管理员和非管理员用户交谈和讨论帮助!这是我的代码:


@command()
  async def support(self, ctx, *, reason = None):
    guildid = ctx.guild.id
    guild = ctx.guild
    user = ctx.author
    amount2 = 1
    await ctx.channel.purge(limit=amount2)
    channel = await guild.create_text_channel(f'Ticket {user}')
    await channel.set_permissions(ctx.guild.default_role, send_messages=False, read_messages=False)
    perms = channel.overwrites_for(user)
    await channel.set_permissions(user, view_channel=not perms.view_channel)
    await channel.set_permissions(user, read_message_history=not perms.read_message_history)
    await channel.set_permissions(user, send_messages=not perms.send_messages)
    await channel.send(f"{user.mention}")
    supem = discord.Embed(title=f"{user} requested support.", description= "", color=0x00ff00)
    supem.add_field(name="Reason", value=f"``{reason}``")
    supem.set_footer(text=f"Either an admin or support staff will be with you shortly...")
    await channel.send(embed=supem)

但我无法获得工作权限,我希望用户能够看到频道、发送消息和查看消息历史记录。请解释为什么我的权限设置部分不起作用。我没有收到任何错误,它只是没有分配 view_channel 权限。

标签: pythonpermissionsdiscord.pychanneluser-permissions

解决方案


推荐阅读