Help Needed With A Send Message (Python) Function For Posting to Twitch

Hello all!

I posted this yesterday, but received no replies. Currently, I can no longer see the message on the board, hence why I’ve posted again today. Apologies if this is considered bad use of this site.

Essentially, I have a bot for connecting to a Twitch channel. With it, I’m attempting to get it to post text strings (random silly jokes) or links (from my social / Youtube) on a timer, but unfortunately cannot seem to get the messaging function quite right. The messaging function works fine in console without the function header, though! Can someone have a look and walk me through why it’s not working and perhaps provide an explanation? A method would obviously be wonderful, too. I’m also not the most experienced in Python and the core of the bot is from a tutorial, so I don’t quite understand everything going on, but understand programming concepts. So, feel free to explain like crazy, even if you believe it might sound patronising! I’m here to learn and get s**t done. Haha.

The most difficult thing about such a function is the lack of examples on the internet about messaging. Sure, there are examples of sending messages based on a reaction to something, but no pure messaging function. There are also explanations related to sockets, but this bot’s implementation is a little different in some ways. Of course, I could be looking in the wrong places, or unlucky.

Below has the code with the main module and messenger function. They’re in the same code block for simplicity, but I eventually aim to place them in separate modules in case the while loop in the messenger module causes any complications.

Code:

from irc.bot import SingleServerIRCBot
from requests import get
import time

NAME = "" 
OWNER = ""

class Bot(SingleServerIRCBot):
    def __init__(self):
        self.HOST = "irc.chat.twitch.tv"
        self.PORT = 6667
        self.USERNAME = NAME.lower()
        self.CLIENT_ID = ""
        self.TOKEN = ""
        self.CHANNEL = f"#{OWNER}"
        
        url = f"https://api.twitch.tv/kraken/users?login={self.USERNAME}"
        headers = {"Client-ID": self.CLIENT_ID, "Accept": "application/vnd.twitchtv.v5+json"}
        resp = get(url, headers=headers).json()
        self.channel_id = resp["users"][0]["_id"]
         
        super().__init__([(self.HOST, self.PORT, f"oauth:{self.TOKEN}")], self.USERNAME, self.USERNAME)
        
    def on_welcome(self, cxn, event):
        for req in ("membership", "tags", "commands"):
            cxn.cap("REQ", f":twitch.tv/{req}")
            
        cxn.join(self.CHANNEL)
        self.send_message("Now online.")
        print(" now online.")
        
    def send_message(self, message):
        self.connection.privmsg(self.CHANNEL, message)
        

def SequencedLink(self, bot, message):
    while True:
        links = ["1", "2", "3", "4"]
    for i in range(len(links)):
        time.sleep(10)
        self.privmsg(f"A sequenced link: {(links[i])}")
        print(f"A sequenced link: {(links[i])}")
        continue
        
if __name__ == "__main__":
    bot = Bot()
    bot.start()

I can only reply within the next hour, as I’ve got other things to do, but I should be able to check this tomorrow morning at the earliest!

Thanks everyone!