如何使presences循环?我希望它每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=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 :)")