# 40165: Channel mode not requested when attaching Identifier: `channel_mode_not_requested_when_attaching` Publishing a message, object, or annotation — or entering presence — was rejected because the client did not request the matching channel mode when it attached. The credentials permit the operation; the mode that enables it was not requested. ## What you should do Update the client so that when it attaches to the channel it requests the [channel mode](https://ably.com/docs/channels/options.md#modes) the operation needs. The error message names the operation that was refused — most commonly, publishing a message needs the `PUBLISH` mode, and entering, updating, or leaving presence needs the `PRESENCE` mode. This is not a capability problem, so changing the token or key's capability will not help — the credentials already grant the operation. ## Why it happens This error means the channel mode required to perform the operation was not among those the client requested when it attached — either because it requested a narrower set of modes (for example attaching to subscribe only and then publishing), or because the mode is not one of the [defaults](https://ably.com/docs/channels/options.md#modes) applied when no modes are specified. The credentials grant the operation; only the attach was missing the mode, so the fix is to request the required mode when attaching rather than to widen the credentials. ## What you'll see The error is reported with code 40165 and HTTP status 401. The message names the operation and the missing mode, for example `Unable to publish a message as client did not request the PUBLISH mode when attaching` or `Unable to enter, update or leave presence as client did not request the PRESENCE mode when attaching`; the object and annotation variants name the `OBJECT_PUBLISH` and `ANNOTATION_PUBLISH` modes.