给定一个不和谐消息id和一个通道id,是否有一种方法可以找到同一不和谐通道的前一条消息?
消息ids在老虎中,我的印象是,消息ids是单调增加的。因此,如果有一种方法可以查找一个通道接收到的所有消息id,我认为它就像找到低于您感兴趣的id的最高值一样简单。
发布于 2020-11-06 14:59:01
我不确定你是想找到消息本身的内容还是之前的消息,但是你可以在txt_channel.history 这里上读到更多
历史记录使您能够看到文本通道的消息历史记录。
因此,如果您想使用特定消息的id查找其内容,可以这样做:(当然,您需要获取文本通道,您可以查看这里)
async for msg in txt_ch.history(limit=[how many messages back you want the loop to go]):
if msg.id == ID_OF_MSG: # you found the message
print("the message with the id has been found")现在,这个代码^^将指向您使用当前id提供的消息,但是如果您想在该消息之前获得消息,只需添加以下内容:
async for msg in txt_ch.history(limit=[how many messages back you want the loop to go]):
found_message = False
if msg.id == ID_OF_MSG: # you found the message
found_message =True
elif found_message:
found_message = False
print("previous message")当然,您可以将打印的最后一行更改为以下内容:
print(msg.content)要看它的内容,或者你可以把它发送回频道,这取决于你。
side :我尝试过测试它,但似乎消息的id并不是一个接一个,所以您不能执行id-1来获取上一条消息id。
https://stackoverflow.com/questions/64715613
复制相似问题