我怎样才能让机器人写下它处于活动状态的服务器数量? (Discord.py重写)
How can I make the bot write on how many servers it is active in its status? (Discord.py Rewrite)
我想做的实际上是写我的消息和有多少服务器在线的机器人。
我的代码:
status = cycle([f"I am online on {len(bot.guilds)} servers!","Second Status")
@bot.event
async def on_ready():
print("Logged in as: " + bot.user.name + "\n")
await change_status.start()
@tasks.loop(seconds = 30)
async def change_status():
await bot.change_presence(activity = discord.Game(next(status)))
当我尝试这样做时,Bot 状态如下:
I am online on 0 servers!
每次循环重复时,机器人都会说:
I am online on 0 servers!
但该机器人目前在 3 个服务器上在线。我该如何解决这个问题?
在函数中定义状态,以便在机器人准备就绪后不断更新和加载。
status = 0
@bot.event
async def on_ready():
print("Logged in as: " + bot.user.name + "\n")
await change_status.start()
@tasks.loop(seconds = 30)
async def change_status():
statuses = [f"I am online on {len(bot.guilds)} servers!", "Second Status"]
if status + 1 > len(statuses):
status = 0
await bot.change_presence(activity = discord.Game(statuses[status]))
status += 1
我想做的实际上是写我的消息和有多少服务器在线的机器人。
我的代码:
status = cycle([f"I am online on {len(bot.guilds)} servers!","Second Status")
@bot.event
async def on_ready():
print("Logged in as: " + bot.user.name + "\n")
await change_status.start()
@tasks.loop(seconds = 30)
async def change_status():
await bot.change_presence(activity = discord.Game(next(status)))
当我尝试这样做时,Bot 状态如下:
I am online on 0 servers!
每次循环重复时,机器人都会说:
I am online on 0 servers!
但该机器人目前在 3 个服务器上在线。我该如何解决这个问题?
在函数中定义状态,以便在机器人准备就绪后不断更新和加载。
status = 0
@bot.event
async def on_ready():
print("Logged in as: " + bot.user.name + "\n")
await change_status.start()
@tasks.loop(seconds = 30)
async def change_status():
statuses = [f"I am online on {len(bot.guilds)} servers!", "Second Status"]
if status + 1 > len(statuses):
status = 0
await bot.change_presence(activity = discord.Game(statuses[status]))
status += 1