gpt4 book ai didi

python - 我怎样才能使状态循环?

转载 作者:行者123 更新时间:2023-12-04 04:11:11 24 4
gpt4 key购买 nike

我怎样才能使状态循环?我希望它每 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 :)")

关于python - 我怎样才能使状态循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61694767/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com