-1

I'm new at bot creating so sry if quesrion is stupid

Bot showing incorrect number of servers(showing 0) when starting 1 code but when starting 2 code it shows correctly, how to change 1 code that it will show correctly help pls

status = cycle( [f' on { len(client.guilds) } servers', '~help'] )
@tasks.loop( seconds = 5 )
async def changeStatus():
    await client.change_presence( activity = discord.Activity( type = discord.ActivityType.playing, name = next(status) ) )
 
@client.event
async def on_ready():
    print( 'bot connected' )
    changeStatus.start()
---------------------------------------------------------------------------------------------------------
@client.event
async def on_ready():
    print( 'bot connected')

    await client.change_presence( activity = discord.Game( f' on { len(client.guilds) } servers | ~help ') )

Workin code but it isn't updating 5 sec if someone need help with updating check another my questions

async def changeStatus():
    status = cycle( [f' on { len(client.guilds) } servers', '~help'] )
    await client.change_presence( activity = discord.Activity( type = discord.ActivityType.playing, name = next(status) ) )

@client.event
async def on_ready():
    print( 'bot connected' )
    changeStatus.start()

2 Answers 2

2

The python interpreter will only run over

status = cycle( [f' on { len(client.guilds) } servers', '~help'] ) 

once, as it is defined as a global variable. This means that len(client.guilds) will always be the same number. And since the interpreter runs over this, before on_ready() was called, the value of this is 0. To fix this, put the declaration of status into your changeStatus() function.

@tasks.loop( seconds = 5 )
async def changeStatus():
    status = cycle( [f' on { len(client.guilds) } servers', '~help'] )
    await client.change_presence( activity = discord.Activity( type = discord.ActivityType.playing, name = next(status) ) )
1
  • Thanks, now it showing correct, but not changing every 5 sec
    – Luigi
    May 5, 2021 at 11:22
2

You can't change it that fast. It is considered API abuse, against TOS i think. Try doing a more reasonable interval like 3 minutes.

2
  • The ratelimit for chaging presences is 5 requests per 1 minute per session iirc, so changing it every 12 seconds should be enough May 5, 2021 at 13:00
  • but when i use my first code and replase for example 'status1' and 'status2' it works good, it depend when you use client.guilds?
    – Luigi
    May 5, 2021 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.