【问题标题】:Change the permissions of a discord text channel with discord.py使用 discord.py 更改不和谐文本频道的权限
【发布时间】:2019-10-11 11:59:12
【问题描述】:

我希望创建一个命令,允许使用 discord.py 修改特定文本通道 discord 的权限。例如,禁用在特定频道中发送消息。

我查看了 discord.py 的文档,发现有一个 PermissionOverwrite 类 (https://discordpy.readthedocs.io/en/latest/api.html?highlight=app#permissionoverwrite) 允许在权限级别执行一些操作(尤其是函数更新)

@client.command()
async def perm(ctx):
        perms = discord.Permissions()
        ctx.channel.perms.update(send_messages=False)

命令引发异常:AttributeError: 'TextChannel' object has no attribute 'perms'

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    使用TextChannel.set_permissions:

    @client.command()
    async def perm(ctx):
        await ctx.channel.set_permissions(ctx.guild.default_role, send_messages=False)
    

    【讨论】:

      猜你喜欢
      • 2020-05-07
      • 1970-01-01
      • 1970-01-01
      • 2020-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-04
      • 2023-03-21
      相关资源
      最近更新 更多