javascript - 未定义获取 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 命令吗?
解决方案
正如您已经提到自己的那样,您在以下行中输入了一个错字:
client.command.get('embed').execute(message, args, Discord)
简单地制作它
client.commands.get('embed').execute(message, args, Discord)
应该修复错误。
你后来提到一个错误说'无法读取未定义的属性'执行''
这仅仅意味着找不到“嵌入”命令。
您command.name
在代码中将其设置为较早,因此请检查嵌入命令文件中的“名称”属性是否确实设置为“嵌入”。
如果您无法自己修复此问题,则从嵌入命令文件提供附加代码会很有帮助。
推荐阅读
- css - 如何在已发布的网站上更改 css 类名称
- entity-framework - 第三方库处理上下文
- unit-testing - 如何为 @Query 方法编写 JUnit 测试用例
- wordpress - 如何阻止 wp_insert_post 插入同一帖子三次?
- javascript - 从 iframe 中的 iframe 获取动态 id
- html - 如何更改标签的字体粗细
- arrays - 如果存在重复值,如何映射对象?
- google-maps - 在 react-native-maps 中使用原生地图
- mysql - 从每个 user_id 获取最旧的时间戳
- angular - 如何强制 Angular 不封装嵌套规则?