Python function not defined when it should be?
<p>I've looked around and don't really know what else to do. My function is not defined after the place where I call it. I'm thinking its probably something stupid, but I can't find it.</p>
<pre><code>def function1():
    global tobegrouped
    if(len(tobegrouped) &gt;= 2): 
        print(len(tobegrouped)) 
        prs1 = random.choice(tobegrouped)
        print(&quot;got prs1&quot;)
        prs2 = random.choice(tobegrouped)
        print(&quot;got prs2&quot;)
        newgroup = group(prs1, prs2)
        print(&quot;made group&quot;)
        global groups
        groups.append(newgroup)
        print(&quot;appended to group&quot;)
        newgroup.send_message(&quot;Welcome to robinbot, have fun, and don't spam&quot;, self)
    else :
        print(&quot;no group ready yet&quot;)
</code></pre>
<p>And this is where I'm calling it. I've already checked that its past the definition of the function in the file.</p>
<pre><code>if command == '/start':
        #   MAYBE CHECK IF IN GROUP HERE
        global tobegrouped
        tobegrouped.append(chat_id)
        print(&quot;in to be grouped&quot;)
        self.sendMessage(chat_id, &quot;welcome to robin, please wait to be grouped&quot;)
        print(&quot;sent message&quot;)
        function1()
        print(&quot;function1s working&quot;)

                              
</code></pre>
<p>And here is the error just in case you need it</p>
<p><a href="https://i.stack.imgur.com/IoNyk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IoNyk.png" alt="enter image description here" /></a></p>
<p>EDIT: Error as text</p>
<blockquote>
<p>File &quot;bot.py&quot;, line 133, in on_chat_message</p>
<p>function1()</p>
<p>NameError: name 'function1' is not defined</p>
<p>Traceback (most recent call last):</p>
<p>File &quot;bot.py&quot; line 223, in (module)</p>
<p>time.sleep(10)</p>
</blockquote>