首页 > 解决方案 > 未定义获取 discord.js node.js

问题描述

您好,我在获取命令/定义时遇到错误,因为它说获取命令代码是:

const Discord = require('discord.js');
const client = new Discord.Client({ partials: ["MESSAGE", "CHANNEL", "REACTION" ]});
const prefix = '.';

const fs = require('fs');

client.commands = new Discord.Collection();

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

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


client.once('ready', () => {
    console.log('Bot is online');
})

client.on('message', message =>{
    if(!message.content.startsWith(prefix) || message.author.bot) return;

    const args = message.content.slice(prefix.length).split(/ +/);
    const command = args.shift().toLowerCase();

    if(command === 'embed'){
      client.command.get('embed').execute(message, args, Discord)
    }
}),

有人可以帮助我使用未定义的 get 命令吗?

标签: javascriptnode.jsdiscord.js

解决方案


正如您已经提到自己的那样,您在以下行中输入了一个错字:

client.command.get('embed').execute(message, args, Discord)

简单地制作它

client.commands.get('embed').execute(message, args, Discord)

应该修复错误。

你后来提到一个错误说'无法读取未定义的属性'执行''

这仅仅意味着找不到“嵌入”命令。

command.name在代码中将其设置为较早,因此请检查嵌入命令文件中的“名称”属性是否确实设置为“嵌入”。

如果您无法自己修复此问题,则从嵌入命令文件提供附加代码会很有帮助。


推荐阅读