未定义get discord.js node.js

r6vfmomb  于 2021-09-23  发布在  Java
关注(0)|答案(2)|浏览(226)

您好,我在get命令/定义中出错,因为它说get命令代码是:

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命令吗?

iq0todco

iq0todco1#

好的,我实际上修复了将命令更改为命令的问题,但我遇到了另一个错误:无法读取未定义的属性“execute”

qvsjd97n

qvsjd97n2#

正如您已经提到的,您在以下行中输入了一个错误:

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

简单地说

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

应该修复错误。
您后来提到了一个错误,该错误表示“无法读取未定义的”的属性“execute”
这仅仅意味着找不到“嵌入”命令。
你把它设定为 command.name 在代码前面,请检查嵌入命令文件中的'name'属性是否确实设置为'embed'。
如果您自己无法修复此问题,则从嵌入命令文件中提供附加代码会很有帮助。

相关问题