【发布时间】:2021-10-29 11:15:29
【问题描述】:
在discord.py中,你可以初始化一个Client,然后用client.run()运行它。但函数永远不会返回。
如果我只想检索一些消息历史然后在 jupyter notebook 中使用它怎么办?
@bot.command()
async def history(ctx):
counter = 0
messageList=[]
async for message in ctx.channel.history(limit = 100):
print(message.author, message.content)
counter += 1
messageList.append(message)
await ctx.send(f'total **{counter}** messages in this channel.')
# How to return the messageList to my jupyter notebook cell and I start playing with the messageList?
如何返回messageList?
【问题讨论】:
-
我不确定您的意图,您是否要启动机器人然后运行命令并终止机器人(您的代码所描述的内容);或启动机器人,然后在启动时自动获取某个特定频道的频道历史记录并终止机器人(您在描述什么)?
-
我只想返回列表,但是函数 client.run() 和 bot.run() 永远不会返回
-
是的,我知道那部分,但请回答我之前评论中的问题,以进一步帮助您。
-
你说的两种方式都可以,我就是想要返回列表
标签: python jupyter-notebook discord discord.py pycord