2021 年 Discord API 添加了一项新功能 - 线程。假设我有一个线程,我想获取线程中的消息列表。我该怎么做?文档说线程就像“子 channel ”,但线程不实现 channel 方法。线程对象的类型就是Message
。
下面是 Python 程序的示例:
from discord.ext import commands
bot = commands.Bot(command_prefix="$")
@bot.event
async def on_ready():
for guild in bot.get_all_channels():
for channel in guild.text_channels:
async for message in channel.history(limit=100):
if message.content == "My Thread Name":
pass
# TODO get individual messages in the thread
最佳答案
alpha 版本有这个:
...
for thread in channel.threads:
async for message in thread.history()
https://discordpy.readthedocs.io/en/master/api.html#discord.TextChannel.threads
如果你没有使用alpha版本,可以这样安装
$ pip install git+https://github.com/Rapptz/discord.py
您还可以使用库的分支之一:disnake
、nextcord
、pycord
关于python - 如何获取 Discord 线程的消息列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71453160/