javascript - 提供了不正确的登录详细信息
问题描述
嗨,我在 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.
解决方案
您需要将机器人的不和谐标记token_discord
放在最后一行的位置。
如果您不知道从哪里获取不和谐机器人令牌,请转到https://discordapp.com/developers并创建一个应用程序。
推荐阅读
- excel - 从 Access for Excel GetOpenFileName 设置默认文件路径
- rest - VersionOne Rest 查询已删除项目
- rust - 如何在宏中同时获取变量的名称和值?
- ffmpeg - 如果我的计算机在 NAT 之后,如何通过 UDP 使用 RTSP 流式传输视频?
- html - 在 Rmarkdown 中的 html 中添加交叉引用
- sql-server - 是否可以列出在另一个 VIEW 中使用的 VIEWS?
- r - 如何在刻度线下将轴标签居中并将箱线图定位到中心
- javascript - 将 .json 作为数组导入 Typescript
- mysql - 使用 MySQL 查询在 2 个连接之间传输表
- arrays - c 当空格被击中时删除空格功能停止