我怎样才能使呈现循环?

2024-10-03 15:32:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我怎样才能使呈现循环?我希望它每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())

Tags: orclientasyncprefix状态defbotactivity
1条回答
网友
1楼 · 发布于 2024-10-03 15:32:15

如果你还没有找到答案的话,我有办法解决

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 :)")

相关问题 更多 >