如何在discord.py中更改频道权限



我希望bot在调用命令时切换为仅发送消息权限。代码:

@commands.command()
@commands.has_permissions(manage_channels=True)
async def lock(self,ctx):
await ctx.channel.set_permissions(ctx.guild.default_role, send_messages=False)

这是有效的,它将默认角色的发送消息权限更改为false,但也会影响其他权限,它将它们设置为中性(默认(。我不想那样,我希望它只是切换发送消息,并保持一切原样。

使用<文本频道>。oversites_for((获取角色的当前权限,然后将send_message从其拥有的权限设置为False。

@commands.command()
@commands.has_permissions(manage_channels=True)
async def lock(self,ctx):
perms = ctx.channel.overwrites_for(ctx.guild.default_role)
perms.send_messages=False
await ctx.channel.set_permissions(ctx.guild.default_role, overwrite=perms)

最新更新