提供的登录详细信息不正确



嗨,我在不和谐机器人上工作,我有一个问题,我创建了一个环境变量,但 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.

这里有几件事。 不和谐令牌是允许机器人登录的机器人令牌。您可以从开发人员控制台获取它。 令牌存储在本地环境中以确保其安全。此行获取它const token_discord = process.env.token_discord然后使用该令牌登录client.login('token_discord');,这是尝试使用字符串"token_discord"而不是变量token_discord登录。尝试删除其两边的单引号。

您需要将机器人的 discord 令牌放在最后一行显示token_discord的位置。

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

最新更新