我想知道是否有一种方法可以记录在一个特定的discord服务器中发送的每一条消息,并将它们记录到一个txt文件中。到目前为止,我已经有了这段代码,但我认为它只记录正在发送的新消息。我需要它来记录所有的事情
@bot.event
async def on_message(message):
await bot.process_commands(message)
if (message.channel.id == '655864692333477926'):
sentmsg2 = str(message.content)
f=open("speclog.txt", "a+")
for i in range(1):
f.write(sentmsg2 + "\r\n")
您需要在代码中创建一个for循环来读取消息历史记录。这是怎么做的
你可以在这里找到更多信息https://discordpy.readthedocs.io/en/latest/api.html#discord.TextChannel.history
相关问题 更多 >
编程相关推荐