Recents in Beach

How to change discord bot status at intervals (discord.py) - pyGod

Python: Making the bots change its status

In the previous articles, you have learnt to make a discord bot in python, add commands to it and also sending embedded welcome messages when anyone joins the server . 

If you still don't know how to make a discord bot in python , I recommend you should go and read those articles first as I have explained with video examples there and it is also really very easy to do so.

Now talking about today , You will be learning to make bot and set bot status and also make the bot change its status at regular intervals.




CODING IT..............


 import discord   
 from discord.ext import commands, tasks  
 from itertools import cycle  
 client = commands.Bot (command_prefix="-")  
 token = YOUR TOKEN HERE  
 status = cycle(['status 1','status 2' ,'status 3'])  
 @client.event  
 async def on_ready():  
   change_status.start()  
   print(" Bot is online!")  
 @tasks.loop(seconds=10)  
 async def change_status():  
   await client.change_presence(activity=discord.Game(next(status)))  
 client.run(token)  

So what we did here is , 
  • from discord.ext import tasks
  • from itertools import cycle
  • Then we created a variable cycle  where we stored all the status that we want our bot to show .
  • Then we started this loop by change_status.start()  , you can really do this by first creating the task and loop but I started it before creating them ..xd because that doesn't really matter.
  • Then we created our loop @tasks.loop(seconds=10),  you can set the time according to you wish , but don't go below 5 seconds if you don't want your bot to crash 
  • Then we setup this task , to make bot to change presence . 
So , this was it , it is really simple to set status and display them in loop . You can use it more creatively too.

I believe you now know how to make your bot change status .
You can join my discord server if you need any kind of help.
You can checkout my youtube channel for hindi video tutorials of the same.

Thank you very much if you are still reading it. 
Have a Good Day ! 

Post a Comment

0 Comments