【发布时间】:2019-09-03 17:34:10
【问题描述】:
我想问我将如何存储不同服务器的变量,因为我在消息命令上有一个“F”,它将 F 存储在 json 中,以便我可以跟踪它在不同服务器上被调用的次数。我还想知道当机器人关闭时如何将其转储到 json 中,因为现在唯一的转储方法是运行命令 aut.disconnect。
filename = "respectspaid.json"
respects = 0
with open(filename) as f_obj:
respects = json.load(f_obj)
@bot.event
async def on_message(message):
print(f"{message.channel}: {message.author}: {message.author.name}: {message.content}")
cajo_guild = bot.get_guild(ID)
if message.author == client.user:
return
if message.author.bot:
return
if "aut.membercount" == message.content.lower():
await message.channel.send(f"```py\n{cajo_guild.member_count}```")
elif "F" == message.content:
global respects
respects += 1
await message.channel.send(f"```Respects paid: {respects}```")
elif "aut.disconnect" == message.content.lower():
with open(filename, 'w') as f_obj:
json.dump(respects, f_obj)
print("Dumping and closing client...")
await bot.close()
sys.exit()
await bot.process_commands(message)
我在断开机器人(当我关闭我的电脑时)时转储更新的 F 计数并在我运行程序时加载它并在每次发送“F”时更新它但我不知道如何执行此操作在多台服务器上很好。这个机器人将主要用于我朋友的服务器,我让机器人做一些他们想要的笑话,所以我不希望机器人做一些更重的事情。
【问题讨论】:
标签: python python-3.x bots discord.py