【问题标题】:Error when i try to activate my discord bot当我尝试激活我的不和谐机器人时出错
【发布时间】:2021-07-09 08:55:55
【问题描述】:

当我尝试使用提示符中的命令“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?有人可以帮忙吗?

【问题讨论】:

  • 您的代码末尾缺少)

标签: discord bots


【解决方案1】:

我认为您缺少一个右大括号。

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

【讨论】:

    猜你喜欢
    • 2021-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-04
    • 1970-01-01
    • 2021-05-18
    • 2020-09-17
    • 2021-11-11
    相关资源
    最近更新 更多