Home>

I want to change the status every second in discord.py.

Error message
Corresponding source code
@ bot.event
    for i in range (0, 100, 1):
    time.sleep (1)
    await bot.change_presence (activity = discord.Game (name = f "connecting | .help | made by @kocha! # 6958 | {len (bot.guilds)} server | {i} seconds passed"))
What I tried

Because it is an indentation error
for i in range (0, 100, 1):
I erased the indent before
SyntaxError: invalid syntax
Was a syntax error ...

Supplementary information (FW/tool version, etc.)

python 3.9.0
discord 1.5.1.
VScode 2019

  • Answer # 1

    @ bot.event
    async def foge ():
      for i in range (0, 100):
        time.sleep (1)
        await bot.change_presence (activity = discord.Game (name = f "connecting | .help | made by @kocha! # 6958 | {len (bot.guilds)} server | {i} seconds passed"))


    Isn't it like this?
    @ bot.eventIs a decorator, which is a rule to put before a function.
    And let's specify the block with indent for the part you want to iterate with the for statement.