如何使我的自机器人从配置文件中获取令牌,而不是将令牌放入代码中?

发布于 2025-02-14 00:36:13 字数 82 浏览 0 评论 0原文

bot.run(“ token”,bot = false)

如何更改它以从config.json中获取令牌?

bot.run("TOKEN", bot=False)

How do I change that to grab the token from the config.json?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过潦 2025-02-21 00:36:13

这是读取JSON文件的功能:

import json

def load_json(filepath):
    with open(filepath) as f:
        data = json.load(f)
    return data

您可以了解有关JSON 在这里

您可以可以,您可以可以在此处使用:

bot.run(load_json("path/to/file.json")["token"], bot=False)

您的JSON文件应该是这样:

{
    "token": "yourtoken"
}

Here's a function to read json files:

import json

def load_json(filepath):
    with open(filepath) as f:
        data = json.load(f)
    return data

You can learn more about json here

Then you can use that in here:

bot.run(load_json("path/to/file.json")["token"], bot=False)

Your json file should be like this:

{
    "token": "yourtoken"
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文