Error getting when running unrelated subcommand?

I get this TypeError: Cannot read properties of undefined (reading 'colour') at Object.execute (/home/runner/Macron-Bot-Upload/commands/defcon.js:33:44) at Client.<anonymous> (/home/runner/Macron-Bot-Upload/index.js:59:19) at Client.emit (node:events:390:28) at Client.emit (node:domain:475:12) at InteractionCreateAction.handle (/home/runner/Macron-Bot-Upload/node_modules/discord.js/src/client/actions/InteractionCreate.js:81:12) at Object.module.exports [as INTERACTION_CREATE] (/home/runner/Macron-Bot-Upload/node_modules/discord.js/src/client/websocket/handlers/INTERACTION_CREATE.js:4:36) at WebSocketManager.handlePacket (/home/runner/Macron-Bot-Upload/node_modules/discord.js/src/client/websocket/WebSocketManager.js:352:31) at WebSocketShard.onPacket (/home/runner/Macron-Bot-Upload/node_modules/discord.js/src/client/websocket/WebSocketShard.js:481:22) at WebSocketShard.onMessage (/home/runner/Macron-Bot-Upload/node_modules/discord.js/src/client/websocket/WebSocketShard.js:321:10) When running my reset subcommand, despite the logs that create the error not being fired by the subcommand, and when I fire the related sub command theres no error? What?
4 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
MrEthλn
MrEthλn2y ago
My code:
const { Client, SlashCommandBuilder, EmbedBuilder } = require('discord.js')
const { defcons } = require('../config.json');

module.exports = {
data: new SlashCommandBuilder()
.setName('defcon')
.setDescription('Defcon Controls')
.addSubcommand(subcommand =>
subcommand
.setName('set')
.setDescription('Set the defcon level')
.addIntegerOption(option =>
option
.setName('level')
.setDescription('Defcon level')
.addChoices(
{ name: '1', value: 1 },
{ name: '2', value: 2 },
{ name: '3', value: 3 },
{ name: '4', value: 4 },
{ name: '5', value: 5 },
)
.setRequired(true)))
.addSubcommand(subcommand =>
subcommand
.setName('reset')
.setDescription('Sets the defcon to 5')),
async execute(interaction, client) {
const level = interaction.options.getInteger('level');
const currDefcon = defcons["defcon"+level]

console.log("Level: "+level)
console.log("Colour: "+currDefcon["colour"])
const A = new EmbedBuilder()
.setColor(currDefcon["colour"])
.setTitle('**Defcon '+currDefcon["id"]+'**')
.setDescription(currDefcon["description"])
.addFields({ name: '**Security Procedure**', value: `${currDefcon["security"]}` },)
.setTimestamp()

if (interaction.options.getSubcommand() === 'set') {
const channel = client.channels.cache.get("1040646203454525602")
await channel.messages.fetch({ limit: 1 }).then(messages => {
let lastMessage = messages.first();

lastMessage.delete();

})

client.channels.cache.get("1040646203454525602").send({ embeds: [A] });
interaction.reply("Set the defcon to "+level)


if (interaction.options.getSubcommand() === 'reset') {
await channel.messages.fetch({ limit: 1 }).then(messages => {
let lastMessage = messages.first();

lastMessage.delete();

})

const A = new EmbedBuilder()
.setColor("#0000ff")
.setTitle('**Defcon 5**')
.setDescription("No known danger")
.addFields({ name: '**Security Procedure**', value: `Normal procedure` },)
.setTimestamp()


client.channels.cache.get("1040646203454525602").send({ embeds: [A] });

interaction.reply("Reset the defcon to 5")
}
}
},
};
const { Client, SlashCommandBuilder, EmbedBuilder } = require('discord.js')
const { defcons } = require('../config.json');

module.exports = {
data: new SlashCommandBuilder()
.setName('defcon')
.setDescription('Defcon Controls')
.addSubcommand(subcommand =>
subcommand
.setName('set')
.setDescription('Set the defcon level')
.addIntegerOption(option =>
option
.setName('level')
.setDescription('Defcon level')
.addChoices(
{ name: '1', value: 1 },
{ name: '2', value: 2 },
{ name: '3', value: 3 },
{ name: '4', value: 4 },
{ name: '5', value: 5 },
)
.setRequired(true)))
.addSubcommand(subcommand =>
subcommand
.setName('reset')
.setDescription('Sets the defcon to 5')),
async execute(interaction, client) {
const level = interaction.options.getInteger('level');
const currDefcon = defcons["defcon"+level]

console.log("Level: "+level)
console.log("Colour: "+currDefcon["colour"])
const A = new EmbedBuilder()
.setColor(currDefcon["colour"])
.setTitle('**Defcon '+currDefcon["id"]+'**')
.setDescription(currDefcon["description"])
.addFields({ name: '**Security Procedure**', value: `${currDefcon["security"]}` },)
.setTimestamp()

if (interaction.options.getSubcommand() === 'set') {
const channel = client.channels.cache.get("1040646203454525602")
await channel.messages.fetch({ limit: 1 }).then(messages => {
let lastMessage = messages.first();

lastMessage.delete();

})

client.channels.cache.get("1040646203454525602").send({ embeds: [A] });
interaction.reply("Set the defcon to "+level)


if (interaction.options.getSubcommand() === 'reset') {
await channel.messages.fetch({ limit: 1 }).then(messages => {
let lastMessage = messages.first();

lastMessage.delete();

})

const A = new EmbedBuilder()
.setColor("#0000ff")
.setTitle('**Defcon 5**')
.setDescription("No known danger")
.addFields({ name: '**Security Procedure**', value: `Normal procedure` },)
.setTimestamp()


client.channels.cache.get("1040646203454525602").send({ embeds: [A] });

interaction.reply("Reset the defcon to 5")
}
}
},
};
yeah but i get the error when running the /defcon reset but not when I run /defcon set x so it gives me the error when I run the unrelated subcommand yeah i dont see what the problem is it works It doesnt error when I run /defcon set but when I run /defcon reset it does no, its not needed there the level is an option, but it could also be the id from the json yes is nothing, so should I put it within the set cfommand? OH I seee now the reset has no level so its getting a non existant parameter thing thank you also now const level = interaction.options.getInteger('level'); returns null? does sub command options work differently?
MrEthλn
MrEthλn2y ago
When I run it, I think its because I didn't restart but now I did the command doesn't get responded to at all
MrEthλn
MrEthλn2y ago
Yes, I think the } for the first one was going over the resset command though yeah was that thanks again