Reputation: 37
I created a lock channel command but when I test it, it gives me no error and doesn't lock the channel. I searched the internet but couldn't find any working lock commands. Here's my code.
@client.command(pass_context=True)
@commands.has_permissions(manage_channels=True)
async def lock(ctx, channel : discord.TextChannel=None):
channel = channel or ctx.channel
overwrite = channel.overwrites_for(ctx.guild.default_role)
overwrite.send_messages = False
await channel.set_permissions(ctx.guild.default_role, overwrite=overwrite)
await ctx.send('Channel locked.')
Upvotes: 0
Views: 520
Reputation: 4225
You are using set_permissions wrongly, pass in the permissions name and its value.
Overwrites should be used if you want more than 1 target, here it is only 1 so we can directly use the permission name.
Below is the revised code:
@client.command(pass_context=True)
@commands.has_permissions(manage_channels=True)
async def lock(ctx, channel : discord.TextChannel=None):
channel = channel or ctx.channel
await channel.set_permissions(ctx.guild.default_role, send_messages=False)
await ctx.send('Channel locked.')
Upvotes: 1