首页 > 解决方案 > 提供了不正确的登录详细信息

问题描述

嗨,我在 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.

标签: javascriptdiscord.js

解决方案


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

如果您不知道从哪里获取不和谐机器人令牌,请转到https://discordapp.com/developers并创建一个应用程序。


推荐阅读