Splitting multiple chat messages from recv()

Hey All,

I’m working with Python 3 to receive chat messages.

Sometimes, there can be multiple chat messages sent in with one recv() command. In this case, I want to be able to split these messages into a list so that I can iterate over them individually. However, I can’t get them to split.

I’ve tried both splitlines() as well as split(’\r\n’), but they will ultimately remain as a single string rather than a list of strings.

Is there something else I need to split on?

In nodeJS I split around \n only

That might help?

Thanks for the response!

After something like 6 hours, I found my mistake and I’m kicking myself lol. Apparently, I needed to create a separate variable to store the output of the .split() function. I was under the impression that the split() function would transform the variable that I’m using it on into a list.

I’m definitely used to languages that are more rigid than Python and would have expected something like that to throw an error.

Yeah thats not an error really. So python didn’t care

You did a string operation then stored the result no where.

A script linter would pick that up perhaps. But a odd one nethertheless!

Glad you got it going now

I’m using tmi.js in node on my desktop. im trying to write a simple chatbot that listens to channels for specific commands and replies. I’m following this tutorial: https://dev.twitch.tv/docs/irc . For reference, I am testing this bot on my own channel (daalbhath) but the bot is itself a separate account (daalbot) and i generated an OAuth token for the bot account with https://twitchapps.com/tmi/

    const client = new tmi.client(opts);

    // Register our event handlers (defined below)
    client.on('message', onMessageHandler);
    client.on('connected', onConnectedHandler);

    // Connect to Twitch:

    // Called every time a message comes in
    function onMessageHandler (channel, tags, msg, self) {
      if (self) { return; } // Ignore messages from the bot

      // Remove whitespace from chat message
      const command: string = msg.trim();
      try {
        if (command.startsWith('!add-detractors')) {
            const detractors: string[] = command.split(' ').slice(1);
            if (detractors.length === 0) {
            client.say(channel, `Added ${detractors.join(', ')} to the list of detractors dspLeanin`);
          } else if (command.startsWith('!list-detractors')) {
            console.log('received command');
            client.say(channel, `There are currently ${currDetractors.length} known detractors`);
            client.say(channel, `The current detractors are: ${currDetractors.join(', ')}`);
          } else {
            console.log(`${channel}/${tags.username}: ${msg}`);
      } catch (err) {
          console.log(`something went wrong: ${err}`);
          console.log(`msg: ${msg}`);

The bot messages don’t show up in my channel. More specifically, only 1 message showed up and then all subsequent messages did not show up. No error is logged either. When I debugged, I did not see any abnormal behavior. The PRIVMSG call is being made. console.logs show that the onMessage handler is being called per message. Literally the message just does not show up in my channel (daalbhath). I also don’t have followers only or sub only or anything enabled.

If all of you don’t mind then I would like know what happen to this thread why this post is closed before it solved by the community.

The thread wasn’t closed, it was just marked as solved because the original poster no longer has an issue, and the issue they experienced doesn’t seem related to what you’re having issues with.

Thanks for the reply…

OP marked it as solved, it’s not closed as you can post to it.