【发布时间】:2019-06-06 18:40:01
【问题描述】:
我正在尝试创建一个 python discord 机器人,它将每 X 秒检查一次活跃成员,并根据他们的在线时间奖励成员。我正在使用 asyncio 来处理聊天命令,这一切正常。我的问题是找到一种方法来安排每隔 X 秒异步检查一次活动成员
我已经阅读了 asnycio 文档,但这是我第一次使用它,我很难将注意力集中在任务、循环和协同例程等方面。
@client.event
async def on_message(message):
# !gamble command
if message.content.startswith('!gamble'):
...code that works....
# !help command
elif message.content == '!help':
...code that works....
# !balance command
elif message.content == '!balance':
...code that works....
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
# Do this every X seconds to give online users +1 points
async def periodic_task():
TODO
我的目标是让机器人能够处理通过聊天发出的命令,同时每隔 X 秒触发一个与 Discord 服务器中的聊天命令或事件无关的功能。我知道如何使函数内的代码达到我的目标,只是不知道如何触发它
【问题讨论】:
标签: python discord python-asyncio