【问题标题】:Discord.py put all guild id's into json fileDiscord.py 将所有公会 ID 放入 json 文件中
【发布时间】:2021-10-19 18:14:32
【问题描述】:

有没有办法将所有公会 ID 放入一个 json 文件中,只是 id 的。我需要它来执行斜杠命令。

【问题讨论】:

  • 有几件事首先告诉我们你尝试了什么第二件事就是在 client.guilds 中使用循环将所有公会放入我猜的所有 JSON 列表中,但就这样你知道这不是 JSON 的主要用途,此外不建议使用 JSON 安全地存储大量值

标签: json discord.py


【解决方案1】:

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

@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)

【讨论】:

    猜你喜欢
    • 2021-03-11
    • 1970-01-01
    • 2020-12-09
    • 2021-02-03
    • 2021-02-02
    • 1970-01-01
    • 2020-11-11
    • 2021-04-30
    • 1970-01-01
    相关资源
    最近更新 更多