title: AttributeError: 'NoneType' object has no attribute 'send' ,when I try to send a message with a bot to a specific discord channel
body: <p>I tried to send a message with the discord bot to a specific text channel, in these 2 ways but none of the 2 really worked for me.</p>
  <p>Here I leave the 2 ways that I try with the respective errors that it returns for each mode</p>
  <p>1#</p>
  <pre class="lang-py prettyprint-override"><code>
  import time, random, discord
  from datetime import datetime
  from discord.ext import commands
  
  
  async def time_messege(args):
      bot = commands.Bot(command_prefix='.')
      alarmtime = &quot;19:23&quot;
      #greeting_channel = bot.get_channel(&quot;814238156396298310&quot;)
      #channel = bot.get_channel = xxx
  
      client = discord.Client()
  
      while True:
        
          lcltime = datetime.now().strftime('%H:%M')
  
          if lcltime == alarmtime:
  
              #aca pondria el code de detectar canal y enviar
              print(&quot;is time!&quot;)
  
              random_num = random.randint(1, 4)
  
              if random_num == 1:
                  #await greeting_channel.send(&quot;Holi!, como estan chic@s?&quot;)
                  await client.send_message(discord.Object(id='814238156396298310'), &quot;Holi!, como estan chic@s?&quot;)
              elif random_num == 2:
                  #await greeting_channel.send(&quot;Holi!, oCmo va su dia? que me cuentan?&quot;)
                  await client.send_message(discord.Object(id='814238156396298310'), &quot;Holi!, oCmo va su dia? que me cuentan?&quot;)
              elif random_num == 3:
                  #await greeting_channel.send(&quot;Holi!, Como va su dia? que andan haciendo?&quot;)
                  await client.send_message(discord.Object(id='814238156396298310'), &quot;Holi!, Como va su dia? que andan haciendo?&quot;)
              elif random_num == 4:
                  #await greeting_channel.send(&quot;Holi!, como se encuentran?&quot;)
                  await client.send_message(discord.Object(id='814238156396298310'), &quot;Holi!, como se encuentran?&quot;)
  
              time.sleep(90)
  
          else:
              print(&quot;not yet&quot;)
              time.sleep(10)
  
  </code></pre>
  <p>This is the error:</p>
  <pre><code>not yet
  not yet
  not yet
  is time!
  Exception in thread Thread-2:
  Traceback (most recent call last):
    File &quot;C:\Users\Maty0\Anaconda3\lib\threading.py&quot;, line 932, in _bootstrap_inner
      self.run()
    File &quot;C:\Users\Maty0\Anaconda3\lib\threading.py&quot;, line 870, in run
      self._target(*self._args, **self._kwargs)
    File &quot;main_greetings.py&quot;, line 101, in between_callback
      loop.run_until_complete(time_messege(args))
    File &quot;C:\Users\Maty0\Anaconda3\lib\asyncio\base_events.py&quot;, line 616, in run_until_complete
      return future.result()
    File &quot;C:\Users\Maty0\Desktop\h ver 18-03\SmartBot-main\core\modules\greetings.py&quot;, line 30, in time_messege
      await client.send_message(discord.Object(id='814238156396298310'), &quot;Holi!, oCmo va su dia? que me cuentan?&quot;)
  AttributeError: 'Client' object has no attribute 'send_message'
  
  </code></pre>
  <p>2#</p>
  <p>if i use the other code (the commented code, and not the client) it give a similar error</p>
  <p>what i need define 'client' ?</p>
  <pre class="lang-py prettyprint-override"><code>import time, random, discord
  from datetime import datetime
  from discord.ext import commands
  
  
  async def time_messege(args):
      bot = commands.Bot(command_prefix='.')
      alarmtime = &quot;19:36&quot;
      
      greeting_channel = bot.get_channel(&quot;814238156396298310&quot;)
      #channel = bot.get_channel = xxx
  
      #client = discord.Client()
  
  
      while True:
        
          lcltime = datetime.now().strftime('%H:%M')
  
          if lcltime == alarmtime:
  
              #aca pondria el code de detectar canal y enviar
              print(&quot;is time!&quot;)
  
              random_num = random.randint(1, 4)
  
              if random_num == 1:
                  await greeting_channel.send(&quot;Holi!, como estan chic@s?&quot;)
                  #await client.send_message(discord.Object(id='814238156396298310'), &quot;Holi!, como estan chic@s?&quot;)
              elif random_num == 2:
                  await greeting_channel.send(&quot;Holi!, oCmo va su dia? que me cuentan?&quot;)
                  #await client.send_message(discord.Object(id='814238156396298310'), &quot;Holi!, oCmo va su dia? que me cuentan?&quot;)
              elif random_num == 3:
                  await greeting_channel.send(&quot;Holi!, Como va su dia? que andan haciendo?&quot;)
                  #await client.send_message(discord.Object(id='814238156396298310'), &quot;Holi!, Como va su dia? que andan haciendo?&quot;)
              elif random_num == 4:
                  await greeting_channel.send(&quot;Holi!, como se encuentran?&quot;)
                  #await client.send_message(discord.Object(id='814238156396298310'), &quot;Holi!, como se encuentran?&quot;)
  
              time.sleep(90)
  
          else:
              print(&quot;not yet&quot;)
              time.sleep(10)
  </code></pre>
  <p>And with this code, give that error</p>
  <pre><code>
  not yet
  not yet
  not yet
  is time!
  Exception in thread Thread-2:
  Traceback (most recent call last):
    File &quot;C:\Users\Maty0\Anaconda3\lib\threading.py&quot;, line 932, in _bootstrap_inner
      self.run()
    File &quot;C:\Users\Maty0\Anaconda3\lib\threading.py&quot;, line 870, in run
      self._target(*self._args, **self._kwargs)
    File &quot;main_greetings.py&quot;, line 101, in between_callback
      loop.run_until_complete(time_messege(args))
    File &quot;C:\Users\Maty0\Anaconda3\lib\asyncio\base_events.py&quot;, line 616, in run_until_complete
      return future.result()
    File &quot;C:\Users\Maty0\Desktop\h ver 18-03\SmartBot-main\core\modules\greetings.py&quot;, line 33, in time_messege
      await greeting_channel.send(&quot;Holi!, oCmo va su dia? que me cuentan?&quot;)
  AttributeError: 'NoneType' object has no attribute 'send'
  </code></pre>
  <p>What algorithm do you recommend and what should I do to avoid these errors?
  What attribute should I put?</p>
  <p>I use that version of discord library</p>
  <pre><code>Python 3.8.5 (default, Sep  3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
  Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.
  &gt;&gt;&gt; import discord
  &gt;&gt;&gt; discord.__version__
  '1.6.0'
  </code></pre>
  <hr />
  <p>the id is correct</p>
  <p><a href="https://i.stack.imgur.com/Nd4P9.jpg" rel="nofollow noreferrer">enter image description here</a></p>
  <p>I also tried the code that they suggest in the answers, but it keeps giving error...</p>
  <pre class="lang-py prettyprint-override"><code>import time, random, discord
  from datetime import datetime
  from discord.ext import commands
  
  bot = commands.Bot(command_prefix='.')
  
  @bot.command()
  async def time_messege(args):
      
      alarmtime = &quot;20:54&quot;
      
  
      #greeting_channel = bot.get_channel(&quot;814238156396298310&quot;)
  
  
      client = discord.Client()
  
  
      while True:
        
          lcltime = datetime.now().strftime('%H:%M')
  
          if lcltime == alarmtime:
  
              #aca pondria el code de detectar canal y enviar
              print(&quot;is time!&quot;)
  
              random_num = random.randint(1, 4)
  
              if random_num == 1:
                  #await greeting_channel.send(&quot;Holi!, como estan chic@s?&quot;)
                  await client.send_message(discord.Object(id='814238156396298310'), &quot;Holi!, como estan chic@s?&quot;)
              elif random_num == 2:
                  #await greeting_channel.send(&quot;Holi!, oCmo va su dia? que me cuentan?&quot;)
                  await client.send_message(discord.Object(id='814238156396298310'), &quot;Holi!, oCmo va su dia? que me cuentan?&quot;)
              elif random_num == 3:
                  #await greeting_channel.send(&quot;Holi!, Como va su dia? que andan haciendo?&quot;)
                  await client.send_message(discord.Object(id='814238156396298310'), &quot;Holi!, Como va su dia? que andan haciendo?&quot;)
              elif random_num == 4:
                  #await greeting_channel.send(&quot;Holi!, como se encuentran?&quot;)
                  await client.send_message(discord.Object(id='814238156396298310'), &quot;Holi!, como se encuentran?&quot;)
  
              time.sleep(90)
  
          else:
              print(&quot;not yet&quot;)
              time.sleep(10)
  </code></pre>
  <p>The error:</p>
  <pre><code>not yet
  not yet
  not yet
  is time!
  Exception in thread Thread-2:
  Traceback (most recent call last):
    File &quot;C:\Users\Maty0\Anaconda3\lib\threading.py&quot;, line 932, in _bootstrap_inner
      self.run()
    File &quot;C:\Users\Maty0\Anaconda3\lib\threading.py&quot;, line 870, in run
      self._target(*self._args, **self._kwargs)
    File &quot;main_greetings.py&quot;, line 101, in between_callback
      loop.run_until_complete(time_messege(args))
    File &quot;C:\Users\Maty0\Anaconda3\lib\asyncio\base_events.py&quot;, line 616, in run_until_complete
      return future.result()
    File &quot;C:\Users\Maty0\Anaconda3\lib\site-packages\discord\ext\commands\core.py&quot;, line 374, in __call__
      return await self.callback(*args, **kwargs)
    File &quot;C:\Users\Maty0\Desktop\h ver 18-03\SmartBot-main\core\modules\greetings.py&quot;, line 41, in time_messege
      await client.send_message(discord.Object(id='814238156396298310'), &quot;Holi!, como se encuentran?&quot;)
  AttributeError: 'Client' object has no attribute 'send_message'
  </code></pre>
  <p>And if I add this extra parameter in the function, this give thar error:</p>
  <pre><code>Exception in thread Thread-2:
  Traceback (most recent call last):
    File &quot;C:\Users\Maty0\Anaconda3\lib\threading.py&quot;, line 932, in _bootstrap_inner
      self.run()
    File &quot;C:\Users\Maty0\Anaconda3\lib\threading.py&quot;, line 870, in run
      self._target(*self._args, **self._kwargs)
    File &quot;main_greetings.py&quot;, line 101, in between_callback
      loop.run_until_complete(time_messege(args))
    File &quot;C:\Users\Maty0\Anaconda3\lib\asyncio\base_events.py&quot;, line 616, in run_until_complete
      return future.result()
    File &quot;C:\Users\Maty0\Anaconda3\lib\site-packages\discord\ext\commands\core.py&quot;, line 374, in __call__
      return await self.callback(*args, **kwargs)
  TypeError: time_messege() missing 1 required positional argument: 'args'
  </code></pre>