Create A Looping Status And Activity In Discord.py Or Disnake or Pycord

How To Create A Changing Status & Activity In Discord Py

Create a changing looping status task for your discord.py or all other forks of discord.py such as disnake, pycord, etc. All types of status types included.

This article includes all types of activities and Statuses usable in a discord bot. So, let’s get started…

Step 1 – Getting Started

First of all setup the basic bot. Additionally you can check the example.py [if you are using other forks of discord.py then just change the “discord” text from all the over the codes into that fork’s name]

Also make sure to import these:

import discord
import asyncio
from discord.ext import tasks, commands
from discord.ext.commands import Bot
from discord.ext.commands import Context

Step 2 – Setting Up A Task

First of all in bot event: on “on_ready” event, include a new line “status_task.start()“, [if you not added “on_ready” event, then add:

@bot.event()
async def on_ready():
status_task.start() #to start the looping task

Then we need to setup the task. now after that add this structure:

@tasks.loop()
async def status_task() -> None:
#put the upcoming codes here

Now let’s complete the code:

await bot.change_presence(status=STATUS-HERE, activity=ACTIVITY-HERE)
await asyncio.sleep(TIME)

This is the main format and by adding this multiple times you will be able to create a looping task. We just need to change the “STATUS-HERE” and “ACTIVITY-HERE” text to set a status with custom activity. Here’s the list of all available Statuses:

discord.Status.dnd #To set status to DND
discord.Status.idle #To set status to Idle
discord.Status.online #To set status to Online

Here’s The List of all Available Activity Types:

#streaming Activity.
discord.Streaming(name="stream name", url="stream url")

# Gaming Activity.
discord.Game("Name of the Game")

#listening Activity
discord.Activity(type=discord.ActivityType.listening, name="name of the music")

#watching Activity
discord.Activity(type=discord.ActivityType.watching, name="name of the movie")

To understand the codes better, you may check the “example.py” from my GitHub repository:

Looping Status & Activity Task Discord.py

Thanks For Allowing Us To Help You!

If you are confused or want to know something, then let us know in the comment box, we will reach you as soon as possible. Don’t Forget To Subscribe our Newsletter, YouTube Channel, and Like Our Facebook Page To Keep Updated With Awesome Things. Follow us on Twitter to stay updated with the latest news & changes.

Did you like it?

More Reading

Post navigation