[英]discord.js: Cannot read properties of undefined (reading 'toJSON')
I was trying to make a bot with discord.js, and following the tutorial at https://discordjs.guide .我试图用 discord.js 制作一个机器人,并按照https://discordjs.guide上的教程进行操作。
And apparently data.toJSON() wasn't recognized (even though builders are installed)显然 data.toJSON() 没有被识别(即使安装了构建器)
deploy-commands.js:部署命令.js:
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const { token, clientId, guildId } = require('./config.json');
const fs = require('node:fs');
const commands = [];
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
commands.push(command.data.toJSON()); // error here
}
const rest = new REST({ version: '9' }).setToken(token);
(async () => {
try {
console.log('Started refreshing application (/) commands.');
await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
);
console.log('Successfully reloaded application (/) commands.');
}
catch (error) {
console.error(error);
}
})();
[ [
]
]
I had some empty files in my commands folder that were getting read without a data property.我的命令文件夹中有一些空文件,这些文件在没有数据属性的情况下被读取。 I deleted them to solve the problem.
我删除它们以解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.