TypeError: Cannot read properties of undefined (reading 'set') discord.js v13
TypeError: Cannot read properties of undefined (reading 'set') discord.js v13
我正在制作一个机器人,但是出现错误!
TypeError: Cannot read properties of undefined (reading 'set')
at /home/runner/Bot-legal/structures/slas
h.js:12:30
at Array.forEach ()
at module.exports (/home/runner/Bot-legal
/structures/slash.js:7:29)
at /home/runner/Bot-legal/index.js:21:39
at Array.forEach ()
at Object. (/home/runner/Bot-legal/index.js:20:31)
我的密码是
let slash = []
const { readdirSync } = require("fs");
const ascii = require("ascii-table");
let table = new ascii("Slash Commands");
table.setHeading('Slash Command', ' Load status');
module.exports = (client) => {
readdirSync("./Slash/").forEach(dir => {
const commands = readdirSync(`./Slash/${dir}/`).filter(file => file.endsWith(".js"));
for (let file of commands) {
let pull = require(`../Slash/${dir}/${file}`);
if (pull.name) {
client.slash.set(pull.name, pull);
slash.push(pull);
table.addRow(file, '✔️ -> Loaded Slash Command');
} else {
table.addRow(file, `❌ -> missing a help.name, or help.name is not a string.`);
continue;
}
}
});
console.log(table.toString());
client.on("ready",async ()=> {
await client.guilds.cache.get('839096342953328691').commands.set(slash);
})
}
谁能找出错误?
试一试,更改了一些 let
并将它们设为 const
,因为它们永远不会被重新分配
const slash = []
const fs = require("fs");
const ascii = require("ascii-table");
const table = new ascii("Slash Commands").setHeading('Slash Command', ' Load status');
module.exports = client => {
fs.readdirSync("./Slash/").forEach(dir => {
const commands = fs.readdirSync(`./Slash/${dir}/`).filter(file => file.endsWith(".js"));
for (const file of commands) {
const pull = require(`./Slash/${dir}/${file}`); // had too many periods
if (pull.name) {
client.commands.set(pull.name, pull);
slash.push(pull);
table.addRow(file, '✔️ -> Loaded Slash Command');
} else {
table.addRow(file, `❌ -> missing a help.name, or help.name is not a string.`);
continue;
}
}
});
console.log(table.toString());
// Below not needed since they are set above
// client.on("ready", async () => {
// await client.guilds.cache.get('839096342953328691').commands.set(slash);
// })
}
我正在制作一个机器人,但是出现错误!
TypeError: Cannot read properties of undefined (reading 'set') at /home/runner/Bot-legal/structures/slas h.js:12:30 at Array.forEach () at module.exports (/home/runner/Bot-legal /structures/slash.js:7:29) at /home/runner/Bot-legal/index.js:21:39 at Array.forEach () at Object. (/home/runner/Bot-legal/index.js:20:31)
我的密码是
let slash = []
const { readdirSync } = require("fs");
const ascii = require("ascii-table");
let table = new ascii("Slash Commands");
table.setHeading('Slash Command', ' Load status');
module.exports = (client) => {
readdirSync("./Slash/").forEach(dir => {
const commands = readdirSync(`./Slash/${dir}/`).filter(file => file.endsWith(".js"));
for (let file of commands) {
let pull = require(`../Slash/${dir}/${file}`);
if (pull.name) {
client.slash.set(pull.name, pull);
slash.push(pull);
table.addRow(file, '✔️ -> Loaded Slash Command');
} else {
table.addRow(file, `❌ -> missing a help.name, or help.name is not a string.`);
continue;
}
}
});
console.log(table.toString());
client.on("ready",async ()=> {
await client.guilds.cache.get('839096342953328691').commands.set(slash);
})
}
谁能找出错误?
试一试,更改了一些 let
并将它们设为 const
,因为它们永远不会被重新分配
const slash = []
const fs = require("fs");
const ascii = require("ascii-table");
const table = new ascii("Slash Commands").setHeading('Slash Command', ' Load status');
module.exports = client => {
fs.readdirSync("./Slash/").forEach(dir => {
const commands = fs.readdirSync(`./Slash/${dir}/`).filter(file => file.endsWith(".js"));
for (const file of commands) {
const pull = require(`./Slash/${dir}/${file}`); // had too many periods
if (pull.name) {
client.commands.set(pull.name, pull);
slash.push(pull);
table.addRow(file, '✔️ -> Loaded Slash Command');
} else {
table.addRow(file, `❌ -> missing a help.name, or help.name is not a string.`);
continue;
}
}
});
console.log(table.toString());
// Below not needed since they are set above
// client.on("ready", async () => {
// await client.guilds.cache.get('839096342953328691').commands.set(slash);
// })
}