简体   繁体   English

Discord bot.js 中的 BOT 错误(语法错误:无效或意外的令牌)

[英]Discord BOT ERROR in bot.js (SyntaxError: Invalid or unexpected token)

I am programming a Discord bot, i installed the files that i required, but when i put the command node bot.js on the command prompt, there a error.我正在编程 Discord 机器人,我安装了我需要的文件,但是当我将命令 node bot.js 放在命令提示符上时,出现错误。 This is my bot.js file这是我的 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) {
// Nuestro bot necesita saber si ejecutará un
// Escuchará los mensajes que empiecen con ‘¡’
if (message.substring(0, 1) == ‘h’) {
var args = message.substring(1).split(‘ ‘);
var cmd = args[0];
args = args.splice(1);
switch(cmd) {
// !ping
case ‘ping’:
bot.sendMessage({
to: channelID,
message: ‘“Que onda bro, me tiraste vino en la camisa por casualidad? jaja que elocuente’
});
break;
// Agrega cualquier comando si lo deseas
}
}
});

And the error is this:错误是这样的:

C:\Users\patri.M2K606\Desktop\BOTS DISCORD\OCHOA (Musica)>node bot.js
C:\Users\patri.M2K606\Desktop\BOTS DISCORD\OCHOA (Musica)\bot.js:1
var Discord = require(‘discord.io’);


SyntaxError: Invalid or unexpected token
[90m    at wrapSafe (internal/modules/cjs/loader.js:1047:16)[39m
[90m    at Module._compile (internal/modules/cjs/loader.js:1097:27)[39m
[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)[39m
[90m    at Module.load (internal/modules/cjs/loader.js:977:32)[39m
[90m    at Function.Module._load (internal/modules/cjs/loader.js:877:14)[39m
[90m    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)[39m
[90m    at internal/main/run_main_module.js:18:47[39m

Help me, i am new so i can not find the syntax error.帮帮我,我是新手,所以我找不到语法错误。 I've been trying for two hours and it throws the same error.我已经尝试了两个小时,它抛出了同样的错误。

There doesn't seem to be anything wrong with the code other than having wrong quotes.除了引用错误之外,代码似乎没有任何问题。 Try using this code:尝试使用此代码:

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) {
// Nuestro bot necesita saber si ejecutará un
// Escuchará los mensajes que empiecen con ‘¡’
if (message.substring(0, 1) == 'h') {
var args = message.substring(1).split(' ');
var cmd = args[0];
args = args.splice(1);

switch(cmd) {
// !ping
case 'ping':
bot.sendMessage({
to: channelID,
message: '"Que onda bro, me tiraste vino en la camisa por casualidad? jaja que elocuente'"
});
break;
// Agrega cualquier comando si lo deseas
}
}
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM