提供了错误的登录详细信息

时间:2019-12-07 14:39:13

标签: javascript discord.js

嗨,我在discord bot上工作,但遇到一个问题,我创建了一个环境变量,但discord无法登录。您能帮忙吗,我没有找到解决方案,谢谢您的阅读。

const Discord = require('discord.js');
const client = new Discord.Client();
const process = require('process');
const token_discord = process.env.token_discord 

client.on('ready', () => {
  console.log('I am ready!');
});

client.on('message', message => {

  if (message.content === 'ping') {
    message.channel.send('pong');
  };
});

client.on('message', message => {
    if (message.content === '!rip'){

        const attachement = new Discord.Attachment('https://i.imgur.com/w3duR07.png');
        message.channel.send(attachement);
    }
});

client.login('token_discord');
(node:21865) UnhandledPromiseRejectionWarning: Error: Incorrect login details were provided.
    at WebSocketConnection.client.ws.connection.once.event (/Users/lucas/Desktop/discord-shiba/node_modules/discord.js/src/client/ClientManager.js:48:41)
    at Object.onceWrapper (events.js:273:13)
    at WebSocketConnection.emit (events.js:182:13)
    at WebSocketConnection.onClose (/Users/lucas/Desktop/discord-shiba/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:390:10)
    at WebSocket.onClose (/Users/lucas/Desktop/discord-shiba/node_modules/ws/lib/event-target.js:124:16)
    at WebSocket.emit (events.js:182:13)
    at WebSocket.emitClose (/Users/lucas/Desktop/discord-shiba/node_modules/ws/lib/websocket.js:191:10)
    at TLSSocket.socketOnClose (/Users/lucas/Desktop/discord-shiba/node_modules/ws/lib/websocket.js:850:15)
    at TLSSocket.emit (events.js:187:15)
    at _handle.close (net.js:606:12)
(node:21865) 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(). (rejection id: 2)
(node:21865) [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.

2 个答案:

答案 0 :(得分:0)

您需要在最后一行上将机器人的不和谐令牌放在token_discord的位置。

如果您不知道从何处获得不一致的机器人令牌,请转到https://discordapp.com/developers并创建一个应用程序。

答案 1 :(得分:0)

这里有几件事。 僵尸令牌是使您的机器人可以登录的Bot令牌。您可以从开发人员控制台中获取。 令牌存储在本地环境中以确保其安全。该行将其提取const token_discord = process.env.token_discord 然后您使用该令牌登录 client.login('token_discord');但这正尝试使用STRING'token_discord'而不是变量token_discord登录。尝试删除周围的单引号。