javascript - 尝试使用 js 创建一个不和谐的机器人得到错误
问题描述
您好,我正在关注 digitaltrends 网站上有关如何创建不和谐机器人的教程,但出现了一些错误
我遵循的教程在 https://www.digitaltrends.com/gaming/how-to-make-a-discord-bot/
尝试编译和下载必要的依赖项时的错误是
**C:\discordbots>npm install discord.io winston -save**
npm ERR! code EJSONPARSE
npm ERR! file C:\discordbots\package.json
npm ERR! JSON.parse Failed to parse json
npm ERR! JSON.parse Unexpected token “ in JSON at position 3 while parsing near '{
npm ERR! JSON.parse “name”: “PUAGirls-bo...'
npm ERR! JSON.parse Failed to parse package.json data.
npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\eugen\AppData\Roaming\npm-cache\_logs\2020-05-09T21_06_55_511Z-debug.log
**C:\discordbots>npm install discord.io winston -save**
npm WARN saveError ENOENT: no such file or directory, open 'C:\discordbots\package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open 'C:\discordbots\package.json'
npm WARN discordbots No description
npm WARN discordbots No repository field.
npm WARN discordbots No README data
npm WARN discordbots No license field.
+ winston@3.2.1
+ discord.io@2.5.3
added 43 packages from 35 contributors and audited 49 packages in 25.961s
found 0 vulnerabilities
**C:\discordbots>npm install https://github.com/woor/discord.io/tarball/gateway_v6**
npm WARN saveError ENOENT: no such file or directory, open 'C:\discordbots\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\discordbots\package.json'
npm WARN discordbots No description
npm WARN discordbots No repository field.
npm WARN discordbots No README data
npm WARN discordbots No license field.
+ discord.io@2.5.3
updated 1 package and audited 144 packages in 6.168s
found 0 vulnerabilities
C:\discordbots>node bot.js
internal/modules/cjs/loader.js:1193
throw err;
^
SyntaxError: C:\discordbots\auth.json: Unexpected token “ in JSON at position 3
at parse (<anonymous>)
at Object.Module._extensions..json (internal/modules/cjs/loader.js:1190:22)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Module.require (internal/modules/cjs/loader.js:1042:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (C:\discordbots\bot.js:3:12)
at Module._compile (internal/modules/cjs/loader.js:1156:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
结束错误
我怎样才能解决这个问题?我也完成了必要的 .json 文件,但主要的 auth.json 文件中有我的客户端 ID,我真的不想给出它
该机器人的 JavaScript 代码是
var Discord = require('discord.io');
var logger = require('winston');
var auth = require('./auth.json');
// Configure logger settings
logger.remove(logger.transports.Console);
logger.add(new logger.transports.Console,
{
colorize: true
});
logger.level = 'debug';
// Initialize Discord Bot
var bot = new Discord.Client({
token: auth.token,
autorun: true
});
bot.on('ready', function (evt) {
logger.info('Connected');
logger.info('Logged in as: ');
logger.info(bot.username + ' - (' + bot.id + ')');
});
bot.on('message', function (user, userID, channelID, message, evt) {
// Our bot needs to know if it will execute a command
// It will listen for messages that will start with `!`
if (message.substring(0, 1) == '!') {
var args = message.substring(1).split(' ');
var cmd = args[0];
args = args.splice(1);
switch(cmd) {
// !lucy
case 'lucy':
bot.sendMessage({
to: channelID,
message: 'Whatever you do DO NOT buy this girl perfume'
});
break;
// Just add any case commands if you want to..
}
}
});
我还有 36 个这样的命令要做,可能还有更多
解决方案
推荐阅读
- sql-server - 我应该将电子邮件 MessageId 存储为什么 SQL Server 数据类型?
- python - 来自 SQL 的 Pandas 中的按周分组
- python - Plotly 中具有 3D 曲面的正交轴
- javascript - iOS Voiceover 不读取动态加载的内容
- github - 如何从推送到 github 的提交中删除一行代码?
- python - 使用 Airflow 将文件从本地系统上传到 Google Bucket - Python
- node.js - 在我的 MongoDB 中存储成功的 Stripe Payments 并在向用户提供产品之前对其进行验证
- javascript - 如何在 JavaScript 中读取文件夹中的 txt 文件列表?
- java - Maven编译打包后不会将其他类编译成jar
- php - 合并具有相同值的数组