我正在尝试为我的不和谐机器人进行随机任务循环。我已经可以通过顺序排列的结果列表来进行状态更改,但是我正在尝试使其以适当的状态(观看,播放等)显示随机结果。目前,任务确实发生了变化,但是在测试时却无法显示(或做出)随机选择,从而使两个结果之一为空白(即不存在涉及到状态以及“ foo”,“ bar”,“垃圾邮件”,“鸡蛋”,只有空白行会更改为我手动设置的结果。这段代码是用Python 3.6.X编写的,对您的帮助或指导将不胜感激!
def rand_task():
'''random condition picker'''
tasks = [
'playing', 'streaming', 'listening', 'watching'
]
return choice(tasks)
async def status_task():
'''random task looper'''
while True:
_play = ['foo'
]
_stream = ['bar'
]
_watch = ['spam'
]
_listen = ['eggs'
]
status = rand_task()
if status == 'playing':
_name = choice(_play)
_type = '0'
_url = None
elif status == 'streaming':
_name = choice(_stream)
_type = '1'
_url = None
elif status == 'listening':
_name = choice(_watch)
_type = '2'
_url = None
elif status == 'watching':
_name = choice(_listen)
_type = '3'
_url = None
await bot.change_presence(game=d.Game(name='for -help', type=3))
await sleep(2)
await bot.change_presence(game=d.Game(name=_name, url=_url, type=_type))
await sleep(1)
@bot.event
async def on_ready():
await bot.loop.create_task(status_task())
答案 0 :(得分:0)
您的_type
变量是字符串,它们应该是整数。
if status == 'playing':
_name = choice(_play)
_type = 0
_url = None
# etc