Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 机器人程序状态更改为<;0x03EA9488处的itertools.cycle对象>;_Python_Discord_Discord.py - Fatal编程技术网

Python 机器人程序状态更改为<;0x03EA9488处的itertools.cycle对象>;

Python 机器人程序状态更改为<;0x03EA9488处的itertools.cycle对象>;,python,discord,discord.py,Python,Discord,Discord.py,我试图让我的机器人自动更改其不协调状态,但它却更改为 这一切都是在一个齿轮,没有改变状态的代码,它的工作非常好。我没有任何错误 这是我正在使用的代码: import discord from discord.ext import commands, tasks from itertools import cycle status = cycle(['status 1', 'status 2', 'status 3']) class OnReady(commands.Cog): de

我试图让我的机器人自动更改其不协调状态,但它却更改为

这一切都是在一个齿轮,没有改变状态的代码,它的工作非常好。我没有任何错误

这是我正在使用的代码:

import discord
from discord.ext import commands, tasks
from itertools import cycle

status = cycle(['status 1', 'status 2', 'status 3'])

class OnReady(commands.Cog):

    def __init__(self, client):
        self.client = client

    @tasks.loop(seconds=10)
    async def change_status(self):
        await self.client.change_presence(status=discord.Status.idle, activity=discord.Game(status))

    @commands.Cog.listener()
    async def on_ready(self):
        self.change_status.start()
        print('Bot is online.')

def setup(client):
    client.add_cog(OnReady(client))

感谢您的帮助。谢谢。

好的,是的。将状态变量设置为

cycle(['status 1', 'status 2', 'status 3'])
哪一个是

itertools.cycle object
就像上面说的。循环是一个无限的可迭代对象,其工作原理如下:

>>> import itertools
>>> c = itertools.cycle([1, 2, 3])
>>> next(c)
1
>>> next(c)
2
>>> next(c)
3
>>> next(c)
1
我不知道什么是
discord.Game
,但从上下文推断,您可能想要更改
activity=discord.Game(status)
,它调用
discord.Game
,将整个周期作为参数,改为
activity=discord.Game(下一个(状态))