【问题标题】:Discord.py custom statuses animationDiscord.py 自定义状态动画
【发布时间】:2020-10-22 17:14:59
【问题描述】:

我已经开始在 python 中尝试使用 Discordbots,我的一个朋友告诉我,您可以使用 Bot 手动自定义游戏活动。所以这是我的问题: 如果您输入活动1,有没有办法添加到活动2,并且它们在无限循环中每秒交换一次? 谢谢

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

    你可以让它改变,只是不是很快,很多流行的机器人实际上都有变化的状态,但你可能不能那么快地发出请求(而且它可能违反 TOS)。

    更新: 我刚刚使用以下代码对此进行了测试,它在停止之前运行了 5 次(可能是速率受限)

    @client.command()
    async def statusLoop(ctx):
        for i in range(100):
            time.sleep(1)
            await client.change_presence(activity = discord.Activity(type=discord.ActivityType.watching, name=(str(random.choice(list(range(900)))))))
    

    【讨论】:

    • 好吧,感谢您花时间处理我的请求,很遗憾这不起作用,但问题不大,因为它只是一个不错的小细节 xD
    【解决方案2】:

    你必须使用tasks.loop

    下面是代码:

    from discord.ext import tasks
    @bot.event
    async def on_ready():
        print("Online")
        bot.statuses = cycle(['Activity 1', 'Activity 2'])
        change_status.start()
    @tasks.loop(seconds=30)
    async def change_status():
        await bot.wait_until_ready()
        await bot.change_presence(activity=discord.Game(name=next(bot.statuses)))
    

    【讨论】:

      猜你喜欢
      • 2021-03-01
      • 2021-04-12
      • 1970-01-01
      • 1970-01-01
      • 2020-05-20
      • 2021-07-15
      • 1970-01-01
      • 2017-08-22
      • 1970-01-01
      相关资源
      最近更新 更多