【问题标题】:Discord py - Overwrite permissions not affecting the channelDiscord py - 覆盖不影响频道的权限
【发布时间】:2021-08-04 21:25:03
【问题描述】:

我一直在尝试创建具有特定权限的频道。 一切似乎都很好,但是当我进入新创建频道的设置时,它似乎没有任何效果。权限同步和覆盖都不会影响频道。这是为什么 ? 我的代码:

role = discord.utils.get(ctx.guild.roles, name=arg.title())
            if role is None:
                role = await ctx.guild.create_role(name=arg.title())
            channel = discord.utils.get(ctx.guild.voice_channels, name=arg.title())
            if channel:
                if channel not in category.voice_channels:
                    await channel.move(category=category, beginning=True)
                await channel.set_permissions(role, connect=True, view_channel=True)
                await channel.set_permissions(ctx.guild.default_role, connect=False, view_channel=False)
            else:
                overwrites = {
                    ctx.guild.default_role: discord.PermissionOverwrite(connect=False, view_channel=False),
                    role: discord.PermissionOverwrite(connect=True, view_channel=True)
                }
                channel = await category.create_voice_channel(arg.title(), overwrite=overwrites)
            await channel.edit(sync_permissions=False)

PS: 我想将权限同步设置为 False,我只是在创建频道后才找到一种方法。 创建的时候有办法吗?

【问题讨论】:

  • 如果你已经覆盖了权限,permissions_synced已经是false,你不需要再次编辑
  • 不知道谢谢!您还知道为什么我的机器人没有创建具有适当权限的频道吗?

标签: python discord.py


【解决方案1】:

错误是由于关键字中的错误引起的

channel = await category.create_voice_channel(arg.title(), overwrite=overwrites)

overwrite 不是 category.create_voice_channel 的关键字 arg

正确的用法是:

channel = await category.create_voice_channel(arg.title(), overwrites=overwrites)

参考:-

【讨论】:

  • 好的,我认为库会警告我使用不存在的命名参数。谢谢!
猜你喜欢
  • 2020-05-07
  • 2019-10-21
  • 2021-02-01
  • 2018-03-04
  • 2020-01-28
  • 2021-02-06
  • 2020-04-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多