【问题标题】:How can i make presences loop?我怎样才能使存在循环?
【发布时间】:2020-08-24 22:22:00
【问题描述】:

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

【问题讨论】:

标签: python discord


【解决方案1】:

如果你还没有找到答案,我得到了一些应该有用的东西。

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

【讨论】:

    猜你喜欢
    • 2013-08-18
    • 2020-08-14
    • 2019-07-13
    • 2014-05-14
    • 2012-02-27
    • 1970-01-01
    • 2022-12-18
    • 2023-03-23
    • 2017-12-20
    相关资源
    最近更新 更多