如何在命令处理程序中运行嵌入命令

时间:2019-11-12 23:18:24

标签: javascript node.js discord discord.js

好的,对于我的命令处理程序,我有:

bot.commands = new Discord.Collection();

const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
    const command = require(`./commands/${file}`);

    bot.commands.set(command.name, command);
}

bot.on('ready', () => {
    console.log(`${bot.user.username} is eating ${bot.guilds.size} shots of cum`)
    bot.user.setActivity("my girlfriend and her husband have sex", {type: "WATCHING"});
});

bot.on('message', message => {
    let args = message.content.substring(PREFIX.length).split(" ");

    switch (args[0]) {

        case "ping":
            bot.commands.get('ping').execute(message, args);
        break;

        case "myinfo":
                bot.commands.get('myinfo').execute(embed, args);
        break;
    }

“ ping”命令有效,但“ myinfo”命令无效。

我的“ MyInfo”代码为:

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

module.exports = {
  name: "ping",
  description: "says ping!",
  execute(message, bot, args){
    message.channel.sendEmbed(embed);
  const embed = new Discord.RichEmbed()
  .setTitle("User Info")
  .addField("Stupid name you got there", message.author.username)
  .addField("GOT YOUR ID FUCKER", message.author.id)
  .addField("Here's how long you've been on discord'", message.author.createdAt)
  .addField("And here's how long you been annoying", message.author.joinedAt)
  .setThumbnail(message.author.avatarURL)
  .setColor("RANDOM");

}




  }

我得到的错误是:

C:\Users\U\Desktop\Folders\Downloads, Setup, and Uninstall Files\Code\CharlesBot\index.js:33
                bot.commands.get('myinfo').execute(embed, args);
                                          ^

TypeError: Cannot read property 'execute' of undefined
    at Client.<anonymous> (C:\Users\U\Desktop\Folders\Downloads, Setup, and Uninstall Files\Code\CharlesBot\index.js:33:43)
    at Client.emit (events.js:210:5)
    at MessageCreateHandler.handle (C:\Users\U\Desktop\Folders\Downloads, Setup, and Uninstall Files\Code\CharlesBot\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)
    at WebSocketPacketManager.handle (C:\Users\U\Desktop\Folders\Downloads, Setup, and Uninstall Files\Code\CharlesBot\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:105:65)
    at WebSocketConnection.onPacket (C:\Users\U\Desktop\Folders\Downloads, Setup, and Uninstall Files\Code\CharlesBot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:333:35)
    at WebSocketConnection.onMessage (C:\Users\U\Desktop\Folders\Downloads, Setup, and Uninstall Files\Code\CharlesBot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:296:17)
    at WebSocket.onMessage (C:\Users\U\Desktop\Folders\Downloads, Setup, and Uninstall Files\Code\CharlesBot\node_modules\ws\lib\event-target.js:120:16)
    at WebSocket.emit (events.js:210:5)
    at Receiver.receiverOnMessage (C:\Users\U\Desktop\Folders\Downloads, Setup, and Uninstall Files\Code\CharlesBot\node_modules\ws\lib\websocket.js:789:20)
    at Receiver.emit (events.js:210:5)

我正在根据一个教程进行此操作,对node.js不太了解。对于命令处理程序,他只显示了如何进行嵌入,仅显示了普通文本。我知道这可能很简单,但是我已经使用了几个小时。

1 个答案:

答案 0 :(得分:0)

myinfo命令中包含这些内容。我认为您将ping文件复制并粘贴到myinfo文件中,并更改了代码,但是您也需要更改命令的名称和说明。

module.exports = {
  name: "ping",
  description: "says ping!",

您需要使用myinfo值对其进行更改以使其起作用。像name: "myinfo", description: "Displays my info"