How to change activity of a discord.py bot?
Question:
I want to change the bot status from playing to watching. I’ve tried this but it’s still playing status:
import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio
PREFIX = ("$")
bot = commands.Bot(command_prefix=PREFIX, description='Hi')
@bot.event
async def on_ready():
activity = discord.Game(name="Netflix", type=3)
await bot.change_presence(status=discord.Status.idle, activity=activity)
print("Bot is ready!")
bot.run('TOKEN')
Answers:
according to this issue ,game keyword argument in Client.change_presence was renamed to activity so your code should look like
activity = discord.Game(name="Just")
await client.change_presence(status=discord.Status.idle, activity=activity)
The bot can still be Playing X
or Streaming Y
though, just NOT custom status
You can use the following lines of code, depending on which activity you want to change the bot to:
# Setting `Playing ` status
await bot.change_presence(activity=discord.Game(name="a game"))
# Setting `Streaming ` status
await bot.change_presence(activity=discord.Streaming(name="My Stream", url=my_twitch_url))
# Setting `Listening ` status
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name="a song"))
# Setting `Watching ` status
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="a movie"))
Reference:
import discord
from discord.ext import commands
import datetime
from urllib import parse, request
import re
bot = commands.Bot(command_prefix='prefix here', description="desc here")
@bot.event
async def on_ready():
await bot.change_presence(activity=discord.Streaming(name="to keep it a secret", url="http://www.twitch.tv/dheeran2010"))
print('Im Ready')
bot.run('Token here')
Just use:
@client.event
async def on_ready():
await client.change_presence(activity=discord.Streaming(name='Fortnite', url='https://www.twitch.tv/UR_TWITCH_GOES_HERE You cant do YT only Twitch.'))
print("Bot is connected to all of the available servers in the bots mainframe.")
for streaming but for the others I can’t help.
Reminder for everyone, DO NOT change_presence (or make API calls) in on_ready
within your Bot or Client.
Discord has a high chance to completely disconnect you during the READY or GUILD_CREATE events (1006 or 1000 close code) and there is nothing you can do to prevent it.
Instead, set the activity
and status
kwargs in the constructor of these Classes.
Playing ->
activity = discord.Game(name="!help")
Streaming ->
activity = discord.Streaming(name="!help", url="twitch_url_here")
Listening ->
activity = discord.Activity(type=discord.ActivityType.listening, name="!help")
Watching ->
activity = discord.Activity(type=discord.ActivityType.watching, name="!help")
bot = commands.Bot(command_prefix="!", activity=activity, status=discord.Status.idle)
Basically: DO NOT do things in on_ready
.
If you want the normal presence then do this :
await bot.change_presence(activity=discord.Streaming(name="My Stream", url=my_twitch_url))
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name="a song"))
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="a movie"))```
#but if you want to make the bot change status every 5 minutes try this :
async def ch_pr():
await client.wait_until_ready()
statuses = ["Vodka Or beer? || bb:help",f"listening on {len(client.guilds)} server's","Still need help? do bb:guide for more help!"]
while not client.is_closed():
status = random.choice(statuses)
await client.change_presence(activity=discord.Game(name=status))
await asyncio.sleep(5)
client.loop.create_task(ch_pr())
maybe try
client = commands.Bot (command_prefix = "!" , activity = discord.Game(name="your help command here"))
for the playing status
instead of doing it on a command or on ready.
@tasks.loop(seconds=10)
async def statusloop():
await client.wait_until_ready()
await client.change_presence(status=discord.Status.dnd, activity=discord.Activity(type=discord.ActivityType.watching, name=f"s!help"))
await sleep(10)
await client.change_presence(status=discord.Status.dnd, activity=discord.Activity(type=discord.ActivityType.watching, name=f"{len(client.guilds)} guilds!"))
await sleep(10)
statusloop.start()
I want to change the bot status from playing to watching. I’ve tried this but it’s still playing status:
import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio
PREFIX = ("$")
bot = commands.Bot(command_prefix=PREFIX, description='Hi')
@bot.event
async def on_ready():
activity = discord.Game(name="Netflix", type=3)
await bot.change_presence(status=discord.Status.idle, activity=activity)
print("Bot is ready!")
bot.run('TOKEN')
according to this issue ,game keyword argument in Client.change_presence was renamed to activity so your code should look like
activity = discord.Game(name="Just")
await client.change_presence(status=discord.Status.idle, activity=activity)
The bot can still be Playing X
or Streaming Y
though, just NOT custom status
You can use the following lines of code, depending on which activity you want to change the bot to:
# Setting `Playing ` status
await bot.change_presence(activity=discord.Game(name="a game"))
# Setting `Streaming ` status
await bot.change_presence(activity=discord.Streaming(name="My Stream", url=my_twitch_url))
# Setting `Listening ` status
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name="a song"))
# Setting `Watching ` status
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="a movie"))
Reference:
import discord
from discord.ext import commands
import datetime
from urllib import parse, request
import re
bot = commands.Bot(command_prefix='prefix here', description="desc here")
@bot.event
async def on_ready():
await bot.change_presence(activity=discord.Streaming(name="to keep it a secret", url="http://www.twitch.tv/dheeran2010"))
print('Im Ready')
bot.run('Token here')
Just use:
@client.event
async def on_ready():
await client.change_presence(activity=discord.Streaming(name='Fortnite', url='https://www.twitch.tv/UR_TWITCH_GOES_HERE You cant do YT only Twitch.'))
print("Bot is connected to all of the available servers in the bots mainframe.")
for streaming but for the others I can’t help.
Reminder for everyone, DO NOT change_presence (or make API calls) in on_ready
within your Bot or Client.
Discord has a high chance to completely disconnect you during the READY or GUILD_CREATE events (1006 or 1000 close code) and there is nothing you can do to prevent it.
Instead, set the activity
and status
kwargs in the constructor of these Classes.
Playing ->
activity = discord.Game(name="!help")
Streaming ->
activity = discord.Streaming(name="!help", url="twitch_url_here")
Listening ->
activity = discord.Activity(type=discord.ActivityType.listening, name="!help")
Watching ->
activity = discord.Activity(type=discord.ActivityType.watching, name="!help")
bot = commands.Bot(command_prefix="!", activity=activity, status=discord.Status.idle)
Basically: DO NOT do things in on_ready
.
If you want the normal presence then do this :
await bot.change_presence(activity=discord.Streaming(name="My Stream", url=my_twitch_url))
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name="a song"))
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="a movie"))```
#but if you want to make the bot change status every 5 minutes try this :
async def ch_pr():
await client.wait_until_ready()
statuses = ["Vodka Or beer? || bb:help",f"listening on {len(client.guilds)} server's","Still need help? do bb:guide for more help!"]
while not client.is_closed():
status = random.choice(statuses)
await client.change_presence(activity=discord.Game(name=status))
await asyncio.sleep(5)
client.loop.create_task(ch_pr())
maybe try
client = commands.Bot (command_prefix = "!" , activity = discord.Game(name="your help command here"))
for the playing status
instead of doing it on a command or on ready.
@tasks.loop(seconds=10)
async def statusloop():
await client.wait_until_ready()
await client.change_presence(status=discord.Status.dnd, activity=discord.Activity(type=discord.ActivityType.watching, name=f"s!help"))
await sleep(10)
await client.change_presence(status=discord.Status.dnd, activity=discord.Activity(type=discord.ActivityType.watching, name=f"{len(client.guilds)} guilds!"))
await sleep(10)
statusloop.start()