Python 我怎样才能使呈现循环?
我怎样才能使呈现循环?我希望它每5-10秒改变一次状态Python 我怎样才能使呈现循环?,python,discord,Python,Discord,我怎样才能使呈现循环?我希望它每5-10秒改变一次状态 client = commands.Bot(command_prefix=commands.when_mentioned_or(",")) async def presenced(): presences = ["Prefix: ,", "Over people!"] activity = discord.Activity( name=random.choice(presences), type=disco
client = commands.Bot(command_prefix=commands.when_mentioned_or(","))
async def presenced():
presences = ["Prefix: ,", "Over people!"]
activity = discord.Activity(
name=random.choice(presences), type=discord.ActivityType.watching)
await client.change_presence(activity=activity)
client.loop.create_task(presenced())
如果你还没有找到答案的话,我有办法解决
import discord
from discord.ext import commands
import asyncio
import random
client = commands.Bot(command_prefix=commands.when_mentioned_or(","))
async def on_ready():
print("client is online!") # you can add other things to this on_ready listener
client.loop.create_task(presenced()) # start the presenced task when the bot is ready
client.add_listener(on_ready)
async def presenced():
while True:
presences = ["Prefix: ,", "Over people!"]
await client.change_presence(activity=discord.Activity(name=random.choice(presences), type=discord.ActivityType.watching))
await asyncio.sleep(10) # you can of course add some randomizer to this delay
client.run("bot token here :)")
看看这个