#how to make an automated commands basically

1 messages · Page 1 of 1 (latest)

spring perch
#

need to make it so that an api call is made to a site every minute or so, what would i need to use? @commands.slash_command isnt going to work lmao

astral stratusBOT
#
from disnake.ext import tasks, commands

class MyCog(commands.Cog):

    def __init__(self, bot):
        self.bot = bot
        self.index = 0
        self.printer.start()

    def cog_unload(self):
        self.printer.cancel()

    @tasks.loop(seconds=5.0)
    async def printer(self):
        print(self.index)
        self.index += 1

    @printer.before_loop
    async def before_printer(self):
        print('waiting...')
        await self.bot.wait_until_ready()

    @printer.error
    async def printer_error(self, error):
        formatted = "".join(
        traceback.format_exception(type(error), error, error.__traceback__))
        await self.bot.get_channel(channel_id).send(formatted)


def setup(bot):
    bot.add_cog(MyCog(bot))```
spring perch
#

that looks like some bull

#

what does that example do?

hasty flint
#

it prints every 5 seconds
1
2
3
4
5.. etc

spring perch
#

ah ok

#

so for once a minute, id go @tasks.loop(minutes=1)?

hasty flint
#

Yeah

spring perch
#

ok

spring perch
#

why 1.0?