bots - 对不和谐机器人的编码感到困惑
问题描述
当我正确完成所有操作并正确编写脚本时,当我放置 node 时就会出现。在命令提示符下我什至有一个有效的令牌!!::
(node:8744) UnhandledPromiseRejectionWarning: Error [TOKEN_INVALID]: An invalid token was provided. at Client.login (C:\Users\User\Documents\GitHub TigerDuo\TigerDuo\node_modules\discord.js\src\client\Client.js:204:52) at Object.<anonymous> (C:\Users\User\Documents\GitHub TigerDuo\TigerDuo\index.js:47:5) at Module._compile (internal/modules/cjs/loader.js:1133:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10) at Module.load (internal/modules/cjs/loader.js:977:32) at Function.Module._load (internal/modules/cjs/loader.js:877:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12) at internal/main/run_main_module.js:18:47 (node:8744) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag
--unhandled-rejections=严格(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:8744) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
这是我的脚本,更不用说我设置了heroku和github:
const Discord = require('discord.js');
const bot = new Discord.Client();
const token = 'MyNeverToBeSharedToken';
bot.on('ready', () => {
console.log('Online.')
bot.user.setActivity('the Tiger Duo server!', {
type: "WATCHING"
})
bot.login(process.env.token);
解决方案
尝试安装 dotenv 包
require("dotenv").config()
并将其添加到代码的顶部
推荐阅读
- c++ - 如何防止多个线程在cpp中同时使用单例类实例
- r - 如何在 R 脚本中调用 Windows 终端?
- ios - 即使我已经配置了 Firebase 也没有配置它
- python-2.7 - 如何从 unicode 字符串中删除前缀 u?
- mysql - MySQL JOIN 来自另一个表的值基于该表中原始表的(重复)值
- python - Python 输入包含 NaN、无穷大或对于 dtype float32 而言太大的值
- php - Mysql 和 PHP 选择 Join Count
- firebase - 如何限制 Firebase 存储的下载次数?
- syslog-ng - 使用非文件目标的模板修改消息格式
- python - 有什么理由将导入库作为类属性?