I'm working on a Discord bot using discord.py and I'm trying to set the bot's status without the default 'Playing', 'Watching', 'Listening to' etc., prefixes that Discord adds. My goal is to have a simple status message like "Ready to help! | B!", but I'm encountering issues in achieving this.
Current Approach:
When I set the status using discord.Game, it adds a 'Playing' prefix:
await client.change_presence(activity=discord.Game(name=current_status))
This results in a status like: "Playing Ready to help! | B!", which is not what I want.
Attempted Solution:
I tried using discord.Activity with ActivityType.custom, but it led to no status being displayed:
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.custom, name=current_status))
End Goal Visualization:
I aim for a status display similar to this bot, which does not show any prefix: Pancake bot no prefix status
However, my current approach results in this: My bot
MRE:
import discord
from discord.ext import commands
import asyncio
import random
async def change_presence():
statuses = ["Ready to help! | B!", "Here to help! | B!", "Your friendly bot! | B!", "Ready for commands! |B!"]
while True:
current_status = random.choice(statuses)
await client.change_presence(activity=discord.Game(name=current_status)) # This adds the 'Playing' prefix
# await client.change_presence(activity=discord.Activity(type=discord.ActivityType.custom, name=current_status)) # No status shown
await asyncio.sleep(7200)
intents = discord.Intents.all()
client = commands.Bot(command_prefix=("B!", "b!", "bot!", "Bot!"), intents=intents)
@client.event
async def on_ready():
print("Bot is starting...")
client.loop.create_task(change_presence())
print("Bot is ready for action!")
client.run("your_token_here")
Is there a way in discord.py (or even in JavaScript) to achieve the status without the prefix? Any help or pointers would be greatly appreciated. Thank you!
You can set a custom status using the discord.CustomActivity
class with ActivityType.custom
e.g.
activity = discord.CustomActivity(name="pancake.gg | p!help")
await client.change_presence(activity=activity)
Another way is to use the default discord.Activity
class e.g.
activity = discord.Activity(
type = discord.ActivityType.custom,
name = "Custom Status", # does nothing but is required
state = "pancake.gg | p!help"
)
await client.change_presence(activity=activity)
But the first way is the recommended one. So Your modified code would be
import discord
from discord.ext import commands
import asyncio
import random
async def change_presence():
statuses = ["Ready to help! | B!", "Here to help! | B!", "Your friendly bot! | B!", "Ready for commands! |B!"]
while True:
current_status = random.choice(statuses)
await client.change_presence(activity=discord.CustomActivity(name=current_status)) # This doesn't add any suffixes
# await client.change_presence(activity=discord.Activity(type=discord.ActivityType.custom, name=current_status)) # No status shown
await asyncio.sleep(7200)
intents = discord.Intents.all()
client = commands.Bot(command_prefix=("B!", "b!", "bot!", "Bot!"), intents=intents)
@client.event
async def on_ready():
print("Bot is starting...")
client.loop.create_task(change_presence())
print("Bot is ready for action!")
client.run("your_token_here")
Edit: Upon further inspection, I saw that you already used this but didn't include the state argument which is the actual text to be shown in the status. The name and state are both required (due to API limitation) even though the name does nothing in this context and the state is the actual text that is used