I ran an auto-formatter and a linter on it. Rather than comments, I added docstrings, which can be seen more easily by IDEs and documentation generators like Sphinx.

```
"""Implementation and example usage for a Matrix message sending function."""
# https://matrix-nio.readthedocs.io/en/latest/examples.html#a-basic-client

from logger import get_logger
from nio import AsyncClient, MatrixRoom, RoomMessageText
import os
import asyncio
import datetime as dt

_logger = get_logger()

ELEM_ROOM = os.environ.get("ELEM_ROOM")
ELEM_USR = os.environ.get("ELEM_USR")
ELEM_PSW = os.environ.get("ELEM_PSW")


def send(message: str) -> None:
    """Send message to the Matrix room with environment variable ELEM_ROOM from ELEM_USR user with ELEM_PSW password."""

    async def message_callback_send(room: MatrixRoom, event: RoomMessageText) -> None:
        _logger.info(
            f"Message sent to room {room.display_name} | {room.user_name(event.sender)}: {event.body}"
        )

    async def send_message() -> None:
        client = AsyncClient("https://matrix.org", ELEM_USR)
        client.add_event_callback(message_callback_send, RoomMessageText)
        try:
            _logger.info(await client.login(ELEM_PSW))
        except ValueError as e:
            _logger.error(f"Failed to login - wrong or missing password?\n{e}")
            raise e
        await client.room_send(
            room_id=ELEM_ROOM,
            message_type="m.room.message",
            content={"msgtype": "m.text", "body": message},
        )
        _logger.info(f"Message sent to room {ELEM_ROOM} | {ELEM_USR}: {message}")
        await client.close()

    asyncio.get_event_loop().run_until_complete(send_message())


if __name__ == "__main__":
    msg = f"Hello world! {dt.datetime.now()}"
    send(msg)

```


I renamed msg to message so it didn't conflict with outer scope variables, removed commented out code (one of which wouldn't have logged any new variables anyway since the line below already logged both of them), and removed a redundant parenthesis. I also added typing to the send function, since it was already used in the internal async functions, as well as documentation matching what pydocstyle recommends.
&nbsp;

If you have access to a local matrix server, such as one through Synapse, I could also write a test to ensure the function works without disturbing other users. However, send_message would need to connect to 127.0.0.1, or wherever the local instance is, and additional code would be needed to read messages from that server.
spam fails_task lang_mismatch pii not_appropriate hate_speech sexual_content quality toxicity humor helpfulness creativity violence