I think we're deviating from the main issue, but here's the code of /ipStatistics.js.
import { SlashCommandBuilder, CommandInteraction, PermissionFlagsBits } from 'discord.js';
import { getIpStatistics } from '../../../playerLog.js';
import { logError } from '../../../stringUtils.js';
import { isValidIp, getEmbed } from '../../util.js';
export const data = new SlashCommandBuilder()
.setName('statistics')
.setDescription('Show kick statistics of an IP.')
.setDMPermission(false)
.addStringOption(option => option
.setName('ip')
.setDescription('IP of player.')
.setRequired(true)
.setMinLength(7)
.setMaxLength(15)
);
export async function execute(interaction) {
const ip = String(interaction.options.get('ip', true)?.value);
if (!isValidIp(ip)) return interaction.editReply({
embeds: [getEmbed(false).setTitle(`Error: \`${ip}\` is not a valid IPv4.`)],
ephemeral: true
}).catch(error => logError(error));
const statsObj = getIpStatistics(ip);
const embed = getEmbed(statsObj.doesExist)
.setTitle(statsObj.doesExist
? `Statistics of IP \`${ip}\``
: `Error: could not find IP \`${ip}\` in logs.`)
.setDescription(statsObj.doesExist
? statsObj.description
: null);
return interaction.editReply({
embeds: [embed],
ephemeral: true
}).catch(error => logError(error));
}```
I ran this example (of a slash command) in VSCode to verify the bot doesn't crash after reproducing the error in the output console. To clarify, such tests were done before I pushed the code to the VPS (pm2).
I would share my project if it would lead to a solution. But it's a private repository of another person so I can't (won't) do that.
**Edit:** `interaction.editReply()` because in `bot.js`, the interaction was deferred with `interaction.deferReply({ ephemeral: true })`.