简体   繁体   English

discord.js:无法读取未定义的属性(读取“toJSON”)

[英]discord.js: Cannot read properties of undefined (reading 'toJSON')

Hello,你好,

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.

相关问题 TypeError:无法读取未定义的属性(读取“toJSON”)- Discord.js 斜杠命令 - TypeError: Cannot read properties of undefined (reading 'toJSON') - Discord.js slash commands Discord.js - TypeError:无法读取未定义的属性(读取“设置”) - Discord.js - TypeError: Cannot read properties of undefined (reading 'set') 无法读取未定义(读取 ws)、discord.js 的属性 - Cannot read properties of undefined (reading ws), discord.js 无法读取未定义的属性(读取“获取”)discord.js - Cannot read properties of undefined (reading 'get') discord.js TypeError:无法读取未定义的属性(读取“设置”)Discord.js - TypeError: Cannot read properties of undefined (reading 'set') Discord.js Discord.js:无法读取未定义的属性(读取“删除”) - Discord.js: Cannot read properties of undefined (reading 'remove') Discord.js:TypeError:无法读取未定义的属性(读取“添加”) - Discord.js: TypeError: Cannot read properties of undefined (reading 'add') 无法读取未定义的属性(读取“getTextInputValue”)Discord.js - Cannot read properties of undefined (reading 'getTextInputValue') Discord.js Discord.js,无法读取未定义的属性(读取“编辑”) - Discord.js, Cannot read properties of undefined (reading 'edit') discord.js 错误:无法读取未定义的属性(读取“客户端”) - discord.js error: Cannot read properties of undefined (reading 'client')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM