【问题标题】:I want to make a command handler for embeds, but only one embed works and the others don't我想为嵌入制作一个命令处理程序,但只有一个嵌入有效,而其他嵌入无效
【发布时间】:2020-08-03 15:10:20
【问题描述】:

好的,所以 命令处理程序有效,我知道它是因为我有 3 个有效的命令(2 个是纯文本,一个是嵌入)。我为嵌入做了这个:

case "menta":
          bot.commands.get('menta').execute(msg, args)
break;

我有其他嵌入物,我制作的嵌入物与可用的嵌入物相同,但它们不起作用。 这是有效的嵌入:

const Discord = require("discord.js");

module.exports = {
    name: 'menta',
    description: 'Info sulla menta',
    execute(msg, args) {
        const menta = new Discord.MessageEmbed()
             .setTitle('ERBE')
             .addField('Nome', 'Menta')
             .addField('Proprietá', 'Rompere gli incantesimi e acquisire forza mentale durante i periodi di difficoltà')
             .setColor('#66CD00');
             msg.channel.send(menta);
    },
};

输入mb! menta 即可。 我做了其他2个,但那些不起作用。这是其中之一:

const Discord = require("discord.js");

module.exports = {
    name: 'alloro',
    description: 'Info sull alloro',
    execute(msg, args) {
        const menta = new Discord.MessageEmbed()
             .setTitle('ERBE')
             .addField('Nome', 'Alloro')
             .addField('Proprietá', 'Visioni psichiche e sogni, respinge la negatività e il male.')
             .setColor('#66CD00');
             msg.channel.send(alloro);
    },
};

我收到此错误消息:

C:\Users\U\Desktop\discord bot\commands\aloe_vera.js:12
             msg.channel.send(alloro);
                              ^

ReferenceError: alloro is not defined

对不起,如果这是一个愚蠢的问题,但我对这类事情非常陌生,哈哈

【问题讨论】:

    标签: javascript node.js discord discord.js


    【解决方案1】:

    这个错误的来源很漂亮,很简单,就像消息说的那样:

    execute(msg, args) {
            const menta = new Discord.MessageEmbed()
                 .setTitle('ERBE')
                 .addField('Nome', 'Alloro')
                 .addField('Proprietá', 'Visioni psichiche e sogni, respinge la negatività e il male.')
                 .setColor('#66CD00');
                 msg.channel.send(alloro);
        }
    

    您新创建的 Embed 名为menta,但您尝试发送一个名为 alloro,只需将 const 的名称更改为 alloro 或发送menta emebed(const alloro = ...msg.channel.send(menta))。

    【讨论】:

      猜你喜欢
      • 2021-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多