当我尝试在提示中使用命令“node bot.js”激活我的机器人时,不断收到此错误:
SyntaxError: Unexpected token ')'
←[90m at Object.compileFunction (node:vm:355:18)←[39m
←[90m at wrapSafe (node:internal/modules/cjs/loader:1022:15)←[39m
←[90m at Module._compile (node:internal/modules/cjs/loader:1056:27)←[39m
←[90m at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)←[39m
←[90m at Module.load (node:internal/modules/cjs/loader:972:32)←[39m
←[90m at Function.Module._load (node:internal/modules/cjs/loader:813:14)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)←[39m
←[90m at node:internal/main/run_main_module:17:47←[39m
这是我在 bot.js 文件中的代码:
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) {
case 'The':
bot.sendMessage({
to: channelID,
message: 'Maurend'
});
break;
// Just add any case commands if you want to.
}
bot.on('!DaSimo', function (user, userID, channelID, message, evt) {
bot.uploadFile({
to: themaurend,
file: 'DaSimo.png'
});
}
我找不到语法错误,它必须在 bot 文件中还是可以在 Bot 文件夹中的其他文件中,例如 auth.json 或 package.json?有人可以帮忙吗?
答案 0 :(得分:0)
我认为您缺少一个右大括号。
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) {
case 'The':
bot.sendMessage({
to: channelID,
message: 'Maurend'
});
break;
// Just add any case commands if you want to.
}
bot.on('!DaSimo', function (user, userID, channelID, message, evt) {
bot.uploadFile({
to: themaurend,
file: 'DaSimo.png'
});
} // here to close the if
}) // and here to close bot.on