'Discord.py - await allowed only within async function python

With the next code:

intents = discord.Intents.all()
bot = commands.Bot(command_prefix='!!')

online=####

@tasks.loop(seconds=1)
async def thatloop():
   def sendmsg():
      channel = bot.get_channel(online)
      await channel.send("Hi") 
   sendmsg()

@bot.event
async def on_ready():
   print("Comienza el scrap.")
   try:
       thatloop.start()
   except RuntimeError:
       pass

bot.run('####')

I'm trying to message a discord channel from a function to understand how to fix a bigger issue. What I'm really looking for is to send a embed from a predefined function INSIDE the loop function (The simplest simile is the code above). The error is in the title. I have read everything on this site, but maybe my poor understanding of English is working against me. I tried to put the function outside the loop but the error persists.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source