2024-04-20 02:55:57 发布
网友
我如何在不和.py它将对话保存到文本文件中。在
例如,bot将所有聊天记录保存在一个名为“chatlogs”的文件夹中,而在discordservera中,每当有人说了机器人能看到的东西,机器人就会把它记录在一个名为服务器A.txt当服务器B添加我的bot时,它会生成一个名为服务器B.txt并保存所有服务器B其中的对话。在
在^{}事件中,以追加模式打开文件并写入最新消息。在
from discord.ext import commands bot = commands.Bot(command_prefix='!') @bot.event async def on_message(message): guild = message.guild if guild: path = "chatlogs/{}.txt".format(guild.id) with open(path, 'a+') as f: print("{0.timestamp} : {0.author.name} : {0.content}".format(message), file=f) await bot.process_commands(message) bot.run("token")
在^{} 事件中,以追加模式打开文件并写入最新消息。在
相关问题 更多 >
编程相关推荐