Python How to run script every 30 sec and then send discord msg
I think you should place this at the top of your code because (like @effprime said) your bot will never be online if its under the infinite while loop:
import requests , time , json , sys , discordresult=requests.get('myapi')result.json()results = "soon:tm:"client = MyClient()client.run("mytoken")
To answer your main question, which was "How to run script every 30 sec and then send discrod msg", I'd write a similar while loop:
while True: # Code executed here print ('Done') time.sleep(30) #you pause the code for 30 seconds everytime all the code as been executed.
I'm not sure exactly what you're trying to do, but
while True: # Code executed here print ('done') time.sleep(1)
is going to block any code after this. The loop never ends. Therefore,
client = MyClient()client.run(btoken)print ('done no errors 2')
will never run, and your bot will never come online
I already think that you have your answer but I thought maybe it will help you.
There is also a tasks function in discord.py.This is an example
from discord.ext import tasks, commands bot = commands.Bot(command_prefix="!") class TasksCog(commands.Cog): def __init__(self, bot) -> None: self.bot = bot self.change_doing.start() @tasks.loop(seconds=30) async def things_to_do(self): .... @commands.command() async def some_command(self, ctx): ...bot.add_cog(TasksCog(bot))bot.run("token")