Ron*_*Liu 3 github node.js discord discord.js
我正在尝试制作一个 24/7 在线的不和谐机器人。我正在使用 Heroku 来托管我的不和谐机器人。Heroku 将我的代码上传到 github。但是,显然 github 和 discord 是配对的,并且 github 检测何时在其上发布了不和谐令牌,并且不和谐会自动更改令牌。当令牌更改时,我无法使用我的机器人。
如评论中所述,将您的令牌放在单独的配置文件中,不要将配置提交到 git (所以基本上将配置文件添加到 .gitignore 文件中)
配置文件
{
"prefix": "!",
"token": "your-token-goes-here"
}
Run Code Online (Sandbox Code Playgroud)
.gitignore
config.json
Run Code Online (Sandbox Code Playgroud)
bot.js
const config = require('./config.json');
...
client.login(config.token)
Run Code Online (Sandbox Code Playgroud)
编辑:重要的是你不要与其他人分享你的令牌,如果有人得到了你的令牌并且有一些恶意的意图,他们可以用你的机器人做各种各样的坏事。这是一个链接,您可以在其中阅读有关此内容以及为什么不应该不惜一切代价提供此令牌的原因。 https://github.com/reactiflux/discord-irc/wiki/Creating-a-discord-bot-&-getting-a-token