Change the permissions of a discord text channel with discord.py

最后都变了- 提交于 2020-07-28 04:05:08

问题


I would have liked to make a command that allows to modify the permissions of a particular text channel discord with discord.py. For example, disable sending messages in a specific channel.

I looked at the documentation of discord.py and I saw that there is a PermissionOverwrite class (https://discordpy.readthedocs.io/en/latest/api.html?highlight=app#permissionoverwrite) allowing to do some things at the level of the permissions (notably with the function update)

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

Command raised an exception: AttributeError: 'TextChannel' object has no attribute 'perms'


回答1:


Use TextChannel.set_permissions:

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


来源:https://stackoverflow.com/questions/56300146/change-the-permissions-of-a-discord-text-channel-with-discord-py

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!