DEV Community

Tejas Kathuria
Tejas Kathuria

Posted on • Updated on

Adding Discord Bot Status with Python

About Rich Presence

We all have seen a custom status on a discord bot like 'playing a game' or 'watching a movie', that is known as 'Rich Presence'. We have to enter some lines of code to add a custom rich presence in a Discord Bot. This Post will help you to add a custom rich presence in your discord bot.

How to add it?

To add this, import discord and commands. The client object for the bot has a method change_presence. This is used to change the status of your bot!

For Playing: Use discord.game() for adding playing status. Add the name of the game to the name argument

import discord
from discord.ext import commands

client = discord.Client()

@client.event
async def on_ready():
await client.change_presence(status=discord.Status.Online, activity=discord.game('a video game'))
print('We have logged in as {0.user}'.format(client))

Enter fullscreen mode Exit fullscreen mode

For Streaming: Use discord.Streaming() for adding streaming status with a url argument

Note: Discord only supports streaming links for YouTube and Twitch. The url argument must be formatted as an actual URL. http://www.twitch.tv will work while www.twitch.tv will not. It won’t change the bot status at all.

import discord
from discord.ext import commands
client = discord.Client

@client.event
async def on_ready():
    await client.change_presence(activity=discord.Streaming(name='a movie', url='https://www.twitch.tv/your_channel_here'))
print('We have logged in as {0.user}'.format(client))
Enter fullscreen mode Exit fullscreen mode

For Watching: Use discord.Activity() with the type argument set to discord.ActivityType.watching for the watching status.

import discord
from discord.ext import commands
client = discord.Client

@client.event
async def on_ready():
    await client.change_presence(activity=discord. Activity(type=discord.ActivityType.watching, name='A Movie'))
print('We have logged in as {0.user}'.format(client))
Enter fullscreen mode Exit fullscreen mode

For Listening: Use discord.Activity() with the type argument set to discord.ActivityType.listening for the listening status.

import discord
from discord.ext import commands
client = discord.Client

@client.event
async def on_ready():
    await client.change_presence(activity=discord. Activity(type=discord.ActivityType.listening, name='To Music'))
print('We have logged in as {0.user}'.format(client))
Enter fullscreen mode Exit fullscreen mode

Example code

import discord
from discord.ext import commands

# Change below's prefix with your prefix

client = commands.Bot(command.prefix = 'ENTER YOUR PREFIX')

@client.event
async def on_ready():
await client.change_presence(status=discord.Status.Online, activity=discord.game('a video game'))

# You can change the current status above
client.run('Your Bot Token')
Enter fullscreen mode Exit fullscreen mode

Top comments (3)

Collapse
 
arvinthkrishna profile image
Arvinth Krishna

It's helpful ✨

Collapse
 
ah3 profile image
Abhishek Hari

Great work! Really appreciate this, would be really useful for me!

Collapse
 
tejasdev profile image
Tejas Kathuria

Thanks!