[英]Discord.py - changing status
I want my bot to change status every 5 seconds.我希望我的机器人每 5 秒更改一次状态。 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.提前致谢。
You forgot to start the task.你忘记开始任务了。 You should not be doing it every 5 seconds as it may rate limit you.您不应该每 5 秒执行一次,因为它可能会限制您的速度。 Personally, I change them every 5 minutes.就个人而言,我每 5 分钟更换一次。
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")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.