IsJsonEncodable is not a function
Im pretty new in the discord bot community, so my error might be pretty stupid.
So basically I am making a botstats command and the bot starts just fine but when I run the command it will crash and give this error (image), This is my code:
``ts
import { SlashCommandBuilder } from "@discordjs/builders";
import { CommandInteraction, EmbedBuilder } from "discord.js";
import { SlashCommand } from "../types";
import { getThemeColor } from "../functions";
const command: SlashCommand = {
command: new SlashCommandBuilder()
.setName("stats bot")
.setDescription("Shows bot statistics"),
execute: async (interaction: CommandInteraction) => {
const bot = interaction.client;
const uptime = bot.uptime || 0;
const guildsCount = bot.guilds.cache.size;
const usersCount = bot.users.cache.size;
const embed = new EmbedBuilder()
.setColor(getThemeColor("text"))
.setTitle("Bot Statistics")
.addFields(
{ name: "Uptime", value: formatUptime(uptime) },
{ name: "Servers", value: guildsCount.toString() },
{ name: "Users", value: usersCount.toString() }
)
.setTimestamp()
.setFooter({ text: "Test123", iconURL: interaction.client.user?.avatarURL() || undefined });
await interaction.reply({ embeds: [embed] });
},
cooldown: 10
};
export default command;
function formatUptime(uptime: number): string {
const seconds = Math.floor((uptime / 1000) % 60);
const minutes = Math.floor((uptime / (1000 * 60)) % 60);
const hours = Math.floor((uptime / (1000 * 60 * 60)) % 24);
const days = Math.floor(uptime / (1000 * 60 * 60 * 24));
return
${days}d ${hours}h ${minutes}m ${seconds}s`;
}3 Replies
- 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 OPUpdate discord.js
Thanks! I got it to work