Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Discord.py - changing status

I want my bot to change status every 5 seconds. When I run the code, it does not display any error. I do not know what is wrong because I use same status changing code for an another bot. I have this code:

import discord
from discord.ext import commands, tasks
from itertools import cycle

client = commands.Bot(command_prefix="?")
status = cycle(["status1", "status2"])

@tasks.loop(seconds=5)
async def changeStatus():
    await client.change_presence(status=discord.Status.do_not_disturb, activity=discord.Activity(type=discord.ActivityType.playing, name=next(status)))

@client.event
async def on_ready():
    notificationChannel = client.get_channel(channel_id)
    await notificationChannel.send("Bot booted up!")

client.run("token")

Thanks in advance.

like image 349
JanMacicka Avatar asked Mar 15 '26 23:03

JanMacicka


1 Answers

You forgot to start the task. You should not be doing it every 5 seconds as it may rate limit you. Personally, I change them every 5 minutes.

import discord
from discord.ext import commands, tasks
from itertools import cycle

client = commands.Bot(command_prefix="?")
status = cycle(["status1", "status2"])

@tasks.loop(seconds=5)
async def changeStatus():
    await client.change_presence(status=discord.Status.do_not_disturb, activity=discord.Activity(type=discord.ActivityType.playing, name=next(status)))

@client.event
async def on_ready():
    notificationChannel = client.get_channel(channel_id)
    await notificationChannel.send("Bot booted up!")
    changeStatus.start()

client.run("token")
like image 128
FluxedScript Avatar answered Mar 18 '26 13:03

FluxedScript



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!