【发布时间】:2019-05-14 02:47:35
【问题描述】:
我似乎无法弄清楚如何激活我的后台任务运行时间。如果我让代码在事件之后运行,它应该会改变角色的颜色。但是将其设置为在后台工作总是失败。也没有错误,我的猜测是任务永远不会加载。
#Login and bot initializer
@client.event
async def on_ready():
print('Logged in as')
print(f"Username: {client.user.name}")
print(f"User ID: {client.user.id}")
print('---------------------------------')
#Runtime Background Tasks
async def runtime_background_task():
id=client.get_guild(564683412699480094)
colours = [discord.Colour(0xe91e63),discord.Colour(0x0000FF0),discord.Colour(0x00FF00),discord.Colour(0xFF0000)]
print("BACKGROUND TASK>> Functional")
await client.wait_until_ready()
while not client.is_closed:
i = random.randint(0, len(colours))
await asyncio.sleep(1)
print(i)
for role in id.roles:
if role.name == 'bot':
await role.edit(server=id, role=role, colour=colours[i])
break
【问题讨论】:
-
已禁止变色机器人以避免淹没 API,以防您不知道。
标签: python-3.x background-task discord.py-rewrite