-
Listening to ...
-
Playing ...
-
Streaming ...
-
Watching ...
-
Competing in ...
The presence can be changed only when the bot is connected to discord gateway, so it can successfully send a PRESENCE
gateway event payload to the gateway in order change the bot's presence. Most libraries allow to set the application's presence within the bot constructor!
All discord.py status types can be found here. All discord.py activity types can be found here.
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix="<Your prefix>", status=discord.Status.online)
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix="<Your prefix>", status=discord.Status.invisible)
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix="<Your prefix>", status=discord.Status.dnd)
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix="<Your prefix>", status=discord.Status.idle)
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix="<Your prefix>", status=discord.Status.online, activity=discord.Game(name="with wumpus"))
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix="<Your prefix>", status=discord.Status.online, activity=discord.Streaming(name="Wumpus Stream", url="the streams url"))
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix="<Your prefix>", status=discord.Status.online, activity=discord.Activity(type=discord.ActivityType.listening, name="The wumpus song"))
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix="<Your prefix>", status=discord.Status.online, activity=discord.Activity(type=discord.ActivityType.watching, name="The wumpus movie"))
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix="<Your prefix>", status=discord.Status.online, activity=discord.Activity(type=discord.ActivityType.competing, name="The wumpus competition"))
You can also use the change_presence. method
NOTE: The method should not be used inside of on_ready() as this event can be triggered multiple times after logging in. Resulting in sending multiple of the same
PRESENCE
gateway event payload to the gateway.
A large number of bots having presences that change by themselves after a certain period. In discord.py this can be done using a task loop. You can read more about tasks here.
import discord
from discord.ext import commands, tasks
import random
bot = commands.Bot(command_prefix="<Your prefix>")
bot.changeable_activites = ("Call of Duty: Warzone", "Fall Guys", "Fortnite", "Call of Duty: Black Ops IV", "Sea of Thieves", "League of Legends", "Valorant")
@tasks.loop(minutes=2)
async def change_activity():
await bot.wait_until_ready()
new_activity = random.choice(bot.changeable_activites)
await bot.change_presence(activity=discord.Game(new_activity))
change_activity.start()
- Yes, popular discord.py forks such as
disnake
,nextcord
andpy-cord
also follow the same structure!
- A gap of
75 seconds
is ideal to change the presence of a bot.
- The simple answer is yes. The better answer is no as spamming gateway event payloads to the gateway can result your bot in getting rate-limited from the discord API.