【问题标题】:Confused coding a discord bot对不和谐机器人的编码感到困惑
【发布时间】:2020-08-18 19:58:16
【问题描述】:

当我正确完成所有操作并正确编写脚本时,当我放置 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=strict(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);

【问题讨论】:

  • 您需要更新您的令牌,并且不再共享它,这就像共享您的密码
  • 您似乎发布了敏感/私人信息。请重置您的密码和/或撤销 API 密钥和令牌,因为它们在互联网上发布时被视为已泄露。如果发布了个人身份信息,请edit 删除信息,然后标记您的帖子以供版主编辑修订。

标签: bots discord


【解决方案1】:

尝试安装 dotenv 包

require("dotenv").config()

并将其添加到代码的顶部

【讨论】:

  • 是的,注意它应该被设置在环境中,正是出于上述原因,所以它不会被意外共享(例如 git、StackOverflow 问题等)
猜你喜欢
  • 2021-09-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-17
  • 2017-10-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多