I’m making a discord bot using discords javascript api and everything was working fine up until I got to 5 commands. I keep getting this same error messages and I’m not sure what’s causing them. What’s weird is that occasionally it works but when i restart the bot it stops working. I need some help finding and fixing this issue.
const { Client, GatewayIntentBits, EmbedBuilder, MessageAttachment, SlashCommandBuilder, PermissionsBitsField, Permissions, AttachmentBuilder } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
const server = require('./server.js')
const randomCat = require('random-cat-img');
const redditParse = require("redditparse");
const fs = require('fs');
const token = process.env['token']
client.on("ready", () => {
console.log(client.user.tag + " online")
client.user.setActivity('cooking meth')
const ping = new SlashCommandBuilder()
.setName('ping')
.setDescription('This is a ping command')
const kitten = new SlashCommandBuilder()
.setName('kitten')
.setDescription('Gives a random image of a cat')
const pokemon = new SlashCommandBuilder()
.setName('pokemon')
.setDescription('Syntax: /pokemon *number here*')
.addIntegerOption(option =>
option
.setName('number')
.setDescription('Pokemon number')
.setRequired(true))
const meme = new SlashCommandBuilder()
.setName('meme')
.setDescription('Random memed from r/funny')
const help = new SlashCommandBuilder()
.setName('help')
.setDescription('List every command')
const bugreport = new SlashCommandBuilder()
.setName('bugreport')
.setDescription('Report a bug')
.addStringOption(option =>
option
.setName('content')
.setDescription('Bug')
.setRequired(true))
client.application.commands.create(ping)
client.application.commands.create(kitten)
client.application.commands.create(pokemon)
client.application.commands.create(meme)
client.application.commands.create(help)
client.application.commands.create(bugreport)
})
client.on('interactionCreate', (interaction) => {
if (!interaction.isChatInputCommand()) return;
if (interaction.commandName === 'ping') {
interaction.reply('pong')
}
if (interaction.commandName === 'pokemon') {
const number = interaction.options.getInteger('number')
if (number > 721 || number < 1) {
interaction.reply("This pokemon doesn't exist or is from generation 7 onwards")
return
} else {
interaction.reply({ files: ['pokemon_jpg/' + number + '.jpg'] });
}
}
if (interaction.commandName === 'kitten') {
getKittenImage();
async function getKittenImage() {
let resultObject;
do {
const result = await redditParse.randomPost("cats");
resultObject = JSON.parse(result);
} while (resultObject.type != "image")
console.log(resultObject)
const kittenEmbed = new EmbedBuilder()
.setTitle(resultObject.title)
.setImage(resultObject.image)
.setColor(0x93C54B)
interaction.reply({
embeds: [kittenEmbed]
})
};
}
if (interaction.commandName === 'meme') {
getMemeImage();
async function getMemeImage() {
let resultObject;
do {
const result = await redditParse.randomPost("funny");
resultObject = JSON.parse(result);
} while (resultObject.type != "image")
console.log(resultObject)
const memeEmbed = new EmbedBuilder()
.setTitle(resultObject.title)
.setImage(resultObject.image)
.setColor(0x93C54B)
interaction.reply({
embeds: [memeEmbed]
})
};
}
if (interaction.commandName === 'help') {
const helpEmbed = new EmbedBuilder()
.setTitle("**Commands**")
.setDescription("`/ping` - Testing purposes\n`/kitten` - Sends a random reddit picture of a cat\n`/pokemon` - Sends a picture of the pokemon associated with the given number\n`/meme` - Sends a random meme from reddit\n\nHeisenburger v1.0")
.setColor(0x93C54B);
interaction.reply({
embeds: [helpEmbed]
})
}
if (interaction.commandName === 'bugreport') {
const content = interaction.options.getString('content')
fs.writeFile('bugs.txt', content, err => {
if (err) {
console.error(err);
}
})
}
});
client.login(token)