繁体   English   中英

未定义获取 discord.js node.js

[英]Undefined get 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)
    }
}),

有人可以帮助我使用 undefined get 命令吗?

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

正如您已经提到的那样,您在以下行中打错了字:

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

简单制作

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

应该修复错误。

您后来提到了“无法读取未定义的属性‘执行’”的错误

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

您在代码的前面将其设置为command.name ,因此请检查嵌入命令文件中的 'name' 属性是否确实设置为 'embed'。

如果您自己无法解决此问题,则从嵌入命令文件中提供其他代码会很有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM