# Get the username from senders of messages on the twitch chat

**URL:** <https://discuss.dev.twitch.com/t/get-the-username-from-senders-of-messages-on-the-twitch-chat/31731>\
**Category:** API\
**Created:** [May 20, 2021, 6:44pm UTC](https://discuss.dev.twitch.com/t/get-the-username-from-senders-of-messages-on-the-twitch-chat/31731 "2021-05-20T18:44:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sabrinabm](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/sabrinabm/32/12155_2.png) [@sabrinabm](https://discuss.dev.twitch.com/u/sabrinabm)\
**Post date:** [May 20, 2021, 6:44pm UTC](https://discuss.dev.twitch.com/t/get-the-username-from-senders-of-messages-on-the-twitch-chat/31731/1 "2021-05-20T18:44:36Z")

</div>

I have the function below to get all the text from the chat, I would also like to get the username of the user who sends the message for any message on chat.

what would be the best way to do this?

```
    def on_pubmsg(self, connection, event):
            chatText = self.string_to_list(event.arguments)
            print("searching for commands in chat: ", chatText)   
            command_indicator = '!'
            for text in chatText:
                print(text)
                if command_indicator in text:
                    if text[0] == command_indicator:
                        print("command founded!")
```

---

<div class="post-metadata">

**Author:** ![sabrinabm](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/sabrinabm/32/12155_2.png) [@sabrinabm](https://discuss.dev.twitch.com/u/sabrinabm)\
**Post date:** [May 20, 2021, 7:14pm UTC](https://discuss.dev.twitch.com/t/get-the-username-from-senders-of-messages-on-the-twitch-chat/31731/2 "2021-05-20T19:14:29Z")

</div>

I founded the solution: username = event.source.nick

---

<div class="post-metadata">

**Author:** ![system](https://d2opxh93rbxzdn.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://discuss.dev.twitch.com/u/system)\
**Post date:** [June 19, 2021, 7:14pm UTC](https://discuss.dev.twitch.com/t/get-the-username-from-senders-of-messages-on-the-twitch-chat/31731/3 "2021-06-19T19:14:35Z")

</div>

Closed on June 19, 2021, 7:14pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
