Discord.py 将所有公会ID放入json文件中



是否有办法将所有公会id放入json文件中,只是id。我需要它用于斜杠命令。

这是一个开始,作为一个命令,但你可能想把它改变为一个循环/任务或一个事件,当有一个新的公会。

@client.command()
async def guildsid(ctx):
#SAMPLE_FILE.JSON
#{"name1": 777703449340143420, "name2": 777703449340143420, "name3": 777703449340143420}
a_dictionary = {}
async for guild in client.fetch_guilds():
a_dictionary[guild.name] = guild.id
with open("sample_file.json", "r+") as file:
data = json.load(file)
data.update(a_dictionary)
file.seek(0)
json.dump(data, file)

最新更新