Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从bot发送的随机报价-意外的标识符_Javascript_Node.js_Discord.js_Commando - Fatal编程技术网

Javascript 从bot发送的随机报价-意外的标识符

Javascript 从bot发送的随机报价-意外的标识符,javascript,node.js,discord.js,commando,Javascript,Node.js,Discord.js,Commando,我收到了一条奇怪的错误信息,看起来像这样: const { Command } = require('discord.js-commando'); const { oneLine } = require('common-tags'); const { RichEmbed } = require('discord.js'); const config = require('../../config.json'); var quotes = config.quotes; module.expor

我收到了一条奇怪的错误信息,看起来像这样:

const { Command } = require('discord.js-commando');
const { oneLine } = require('common-tags');
const { RichEmbed } = require('discord.js');
const config = require('../../config.json');
var quotes = config.quotes;


module.exports = class EchoCommand extends Command {
    constructor(client) {
        super(client, {
            name: 'quote',
            group: 'quote',
            memberName: 'quote',
            description: 'Echoes a random Quote.',
            details: oneLine`,
            I'll say out a quote`,
            examples: ['quote']
        });
    }

    const avatarURL = message.author.avatar ? message.author.avatarURL: 'https://discordapp.com/assets/0e291f67c9274a1abdddeb3fd919cbaa.png';
    const embed = new Discord.RichEmbed()
      .setAuthor(`${message.author.tag}`, `${avatarURL}`);
      .setColor(0x0000FF);
      .setDescription(quotes[Math.floor(Math.random() * quotes.length)]);
      .setTimestamp();
    await message.channel.send({
      embed
    });
};
module.exports = class EchoCommand extends Command {
  constructor(client) {
    super(client, {
      name: 'quote',
      group: 'quote',
      memberName: 'quote',
      description: 'Echoes a random Quote.',
      details: oneLine `,
            I'll say out a quote`,
      examples: ['quote']
    });
  }

  async run(message) {
    const avatarURL = message.author.avatar ? message.author.avatarURL : 'https://discordapp.com/assets/0e291f67c9274a1abdddeb3fd919cbaa.png';
    const embed = new Discord.RichEmbed()
      .setAuthor(`${message.author.tag}`, `${avatarURL}`);
    .setColor(0x0000FF);
    .setDescription(quotes[Math.floor(Math.random() * quotes.length)]);
    .setTimestamp();
    await message.channel.send({
      embed
    });
  }
};
aysnc run(message, {arg1, arg2, arg3, ...args}) {...}
SyntaxError:意外的标识符
在createScript上(vm.js:80:10)
在Object.runInThisContext(vm.js:139:10)
在模块处编译(Module.js:616:28)
在Object.Module.\u extensions..js(Module.js:663:10)
在Module.load(Module.js:565:32)
在tryModuleLoad时(module.js:505:12)
在Function.Module.\u加载(Module.js:497:3)
at Module.require(Module.js:596:17)
根据需要(内部/module.js:11:18)
at/home/remix867/bot_commando/node_modules/require all/index.js:52:46
所以它以前工作过,但我已经安装了所有依赖项。Javascript代码如下所示:

const { Command } = require('discord.js-commando');
const { oneLine } = require('common-tags');
const { RichEmbed } = require('discord.js');
const config = require('../../config.json');
var quotes = config.quotes;


module.exports = class EchoCommand extends Command {
    constructor(client) {
        super(client, {
            name: 'quote',
            group: 'quote',
            memberName: 'quote',
            description: 'Echoes a random Quote.',
            details: oneLine`,
            I'll say out a quote`,
            examples: ['quote']
        });
    }

    const avatarURL = message.author.avatar ? message.author.avatarURL: 'https://discordapp.com/assets/0e291f67c9274a1abdddeb3fd919cbaa.png';
    const embed = new Discord.RichEmbed()
      .setAuthor(`${message.author.tag}`, `${avatarURL}`);
      .setColor(0x0000FF);
      .setDescription(quotes[Math.floor(Math.random() * quotes.length)]);
      .setTimestamp();
    await message.channel.send({
      embed
    });
};
module.exports = class EchoCommand extends Command {
  constructor(client) {
    super(client, {
      name: 'quote',
      group: 'quote',
      memberName: 'quote',
      description: 'Echoes a random Quote.',
      details: oneLine `,
            I'll say out a quote`,
      examples: ['quote']
    });
  }

  async run(message) {
    const avatarURL = message.author.avatar ? message.author.avatarURL : 'https://discordapp.com/assets/0e291f67c9274a1abdddeb3fd919cbaa.png';
    const embed = new Discord.RichEmbed()
      .setAuthor(`${message.author.tag}`, `${avatarURL}`);
    .setColor(0x0000FF);
    .setDescription(quotes[Math.floor(Math.random() * quotes.length)]);
    .setTimestamp();
    await message.channel.send({
      embed
    });
  }
};
aysnc run(message, {arg1, arg2, arg3, ...args}) {...}
Config.json只是一个简单的json,其中存储了所有随机引号

问题应该在第20行,我在那里定义了头像URL,但如果我删除这一行,它会在另一行上显示出完全相同的错误


提前感谢:)

使用Commando创建命令时,需要将要执行的代码放入类的
方法中。运行
方法。
在您的情况下,代码应该如下所示:

const { Command } = require('discord.js-commando');
const { oneLine } = require('common-tags');
const { RichEmbed } = require('discord.js');
const config = require('../../config.json');
var quotes = config.quotes;


module.exports = class EchoCommand extends Command {
    constructor(client) {
        super(client, {
            name: 'quote',
            group: 'quote',
            memberName: 'quote',
            description: 'Echoes a random Quote.',
            details: oneLine`,
            I'll say out a quote`,
            examples: ['quote']
        });
    }

    const avatarURL = message.author.avatar ? message.author.avatarURL: 'https://discordapp.com/assets/0e291f67c9274a1abdddeb3fd919cbaa.png';
    const embed = new Discord.RichEmbed()
      .setAuthor(`${message.author.tag}`, `${avatarURL}`);
      .setColor(0x0000FF);
      .setDescription(quotes[Math.floor(Math.random() * quotes.length)]);
      .setTimestamp();
    await message.channel.send({
      embed
    });
};
module.exports = class EchoCommand extends Command {
  constructor(client) {
    super(client, {
      name: 'quote',
      group: 'quote',
      memberName: 'quote',
      description: 'Echoes a random Quote.',
      details: oneLine `,
            I'll say out a quote`,
      examples: ['quote']
    });
  }

  async run(message) {
    const avatarURL = message.author.avatar ? message.author.avatarURL : 'https://discordapp.com/assets/0e291f67c9274a1abdddeb3fd919cbaa.png';
    const embed = new Discord.RichEmbed()
      .setAuthor(`${message.author.tag}`, `${avatarURL}`);
    .setColor(0x0000FF);
    .setDescription(quotes[Math.floor(Math.random() * quotes.length)]);
    .setTimestamp();
    await message.channel.send({
      embed
    });
  }
};
aysnc run(message, {arg1, arg2, arg3, ...args}) {...}
如果将参数添加到命令中,它将如下所示:

const { Command } = require('discord.js-commando');
const { oneLine } = require('common-tags');
const { RichEmbed } = require('discord.js');
const config = require('../../config.json');
var quotes = config.quotes;


module.exports = class EchoCommand extends Command {
    constructor(client) {
        super(client, {
            name: 'quote',
            group: 'quote',
            memberName: 'quote',
            description: 'Echoes a random Quote.',
            details: oneLine`,
            I'll say out a quote`,
            examples: ['quote']
        });
    }

    const avatarURL = message.author.avatar ? message.author.avatarURL: 'https://discordapp.com/assets/0e291f67c9274a1abdddeb3fd919cbaa.png';
    const embed = new Discord.RichEmbed()
      .setAuthor(`${message.author.tag}`, `${avatarURL}`);
      .setColor(0x0000FF);
      .setDescription(quotes[Math.floor(Math.random() * quotes.length)]);
      .setTimestamp();
    await message.channel.send({
      embed
    });
};
module.exports = class EchoCommand extends Command {
  constructor(client) {
    super(client, {
      name: 'quote',
      group: 'quote',
      memberName: 'quote',
      description: 'Echoes a random Quote.',
      details: oneLine `,
            I'll say out a quote`,
      examples: ['quote']
    });
  }

  async run(message) {
    const avatarURL = message.author.avatar ? message.author.avatarURL : 'https://discordapp.com/assets/0e291f67c9274a1abdddeb3fd919cbaa.png';
    const embed = new Discord.RichEmbed()
      .setAuthor(`${message.author.tag}`, `${avatarURL}`);
    .setColor(0x0000FF);
    .setDescription(quotes[Math.floor(Math.random() * quotes.length)]);
    .setTimestamp();
    await message.channel.send({
      embed
    });
  }
};
aysnc run(message, {arg1, arg2, arg3, ...args}) {...}