"invalid string length" error

full code:
import discord from "discord.js";
import fs from "fs";

export default {
name: "commands",
description: "displays commands list",
arguments: "none",
execute(message, args) {
let text = "";

const commandFiles = fs
.readdirSync("src/commands/")
.filter((file) => file.endsWith(".js"));
(async () => {
for (const file of commandFiles) {
const command = await import(`./${file}`);
text += `p/${command.default.name} - ${command.default.description} - command arguments: ${command.default.arguments}\n \n`;
console.log(typeof command.default.name);
}
})();
console.log(text);
const embed = new discord.EmbedBuilder();
embed.setTitle("PepperBot Commands");
embed.setDescription(text);
embed.setColor(0xff0000);
embed.setThumbnail(
"https://cdn.discordapp.com/attachments/755150633191080073/1149152214850469908/Map_Icon.png"
);
message.reply({ embeds: [embed] });
},
};
import discord from "discord.js";
import fs from "fs";

export default {
name: "commands",
description: "displays commands list",
arguments: "none",
execute(message, args) {
let text = "";

const commandFiles = fs
.readdirSync("src/commands/")
.filter((file) => file.endsWith(".js"));
(async () => {
for (const file of commandFiles) {
const command = await import(`./${file}`);
text += `p/${command.default.name} - ${command.default.description} - command arguments: ${command.default.arguments}\n \n`;
console.log(typeof command.default.name);
}
})();
console.log(text);
const embed = new discord.EmbedBuilder();
embed.setTitle("PepperBot Commands");
embed.setDescription(text);
embed.setColor(0xff0000);
embed.setThumbnail(
"https://cdn.discordapp.com/attachments/755150633191080073/1149152214850469908/Map_Icon.png"
);
message.reply({ embeds: [embed] });
},
};
code causing the issue:
(async () => {
for (const file of commandFiles) {
const command = await import(`./${file}`);
text += `p/${command.default.name} - ${command.default.description} - command arguments: ${command.default.arguments}\n \n`;
console.log(typeof command.default.name);
}
})();
(async () => {
for (const file of commandFiles) {
const command = await import(`./${file}`);
text += `p/${command.default.name} - ${command.default.description} - command arguments: ${command.default.arguments}\n \n`;
console.log(typeof command.default.name);
}
})();
error:
6 Replies
d.js toolkit
d.js toolkit15mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
ayeuhugyu
ayeuhugyuOP15mo ago
djs version: 14.13.0 node version: v19.0.0
duck
duck15mo ago
at EmbedBuilder.setDescription given: '',
sounds like you passed an empty string to setDescription
ayeuhugyu
ayeuhugyuOP15mo ago
yeah but im pretty darn sure the string isn't empty
text += `p/${command.default.name} - ${command.default.description} - command arguments: ${command.default.arguments}\n \n`;
text += `p/${command.default.name} - ${command.default.description} - command arguments: ${command.default.arguments}\n \n`;
yknow
duck
duck15mo ago
which is happening asynchronously, resulting in setDescription being called before anything is added to text
ayeuhugyu
ayeuhugyuOP15mo ago
oh
Want results from more Discord servers?
Add your server