Reputation: 305
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'
Upvotes: 7
Views: 25898
Reputation: 61052
Use TextChannel.set_permissions
:
@client.command()
async def perm(ctx):
await ctx.channel.set_permissions(ctx.guild.default_role, send_messages=False)
Upvotes: 9