4 Replies
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Discordjs 14.7.1
Node v16.13.1
Index.js
commands/coins.js
TypeError: Cannot read properties of undefined (reading 'autocomplete')
client.on('interactionCreate', async interaction => {
if (interaction.isAutocomplete()) {
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
}
try {
await command.autocomplete(interaction);
} catch (error) {
console.error(error);
logger.error(error);
}
} else if (interaction.isChatInputCommand()) {
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
logger.error(error);
//await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
});
client.on('interactionCreate', async interaction => {
if (interaction.isAutocomplete()) {
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
}
try {
await command.autocomplete(interaction);
} catch (error) {
console.error(error);
logger.error(error);
}
} else if (interaction.isChatInputCommand()) {
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
logger.error(error);
//await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
});
const { SlashCommandBuilder, PermissionsBitField, PermissionFlagsBits, EmbedBuilder } = require('discord.js');
const { SkillCamps } = require('../../ChannelIDs.json');
module.exports = {
data: new SlashCommandBuilder()
.setName('give-coins')
.setDescription('Give coins to a user')
.addUserOption(option => option
.setName('user')
.setDescription('The user to give coins to')
.setRequired(true),
)
.addIntegerOption(option => option
.setName('amount')
.setDescription('The amount of coins to give')
.setRequired(true),
)
.addStringOption(option => option
.setName('reason')
.setDescription('The reason for giving coins')
.setRequired(true)
.setAutocomplete(true),
),
async autocomplete(interaction) {
console.group('autocomplete');
let choices;
console.log(`SkillCampGuildIds: ${SkillCampGuildIds}`);
const focusedOption = interaction.options.getFocused(true);
console.log(`focusedOption.name: ${focusedOption.name}`);
if (focusedOption.name == 'reason') {
choices = ['Purchase Table Reads', 'Redeem SkillStore Coupon'];
}
await interaction.respond(
choices.map(choice => ({ name: choice, value: choice })),
);
try {
const filtered = choices.filter(choice => choice.startsWith(focusedOption.value));
await interaction.respond(
filtered.map(choice => ({ name: choice, value: choice })),
);
} catch (error) {
console.error("error", error);
}
console.groupEnd();
},
async execute(interaction) {
const user = interaction.options.getUser('user');
const amount = interaction.options.getInteger('amount');
}
}
const { SlashCommandBuilder, PermissionsBitField, PermissionFlagsBits, EmbedBuilder } = require('discord.js');
const { SkillCamps } = require('../../ChannelIDs.json');
module.exports = {
data: new SlashCommandBuilder()
.setName('give-coins')
.setDescription('Give coins to a user')
.addUserOption(option => option
.setName('user')
.setDescription('The user to give coins to')
.setRequired(true),
)
.addIntegerOption(option => option
.setName('amount')
.setDescription('The amount of coins to give')
.setRequired(true),
)
.addStringOption(option => option
.setName('reason')
.setDescription('The reason for giving coins')
.setRequired(true)
.setAutocomplete(true),
),
async autocomplete(interaction) {
console.group('autocomplete');
let choices;
console.log(`SkillCampGuildIds: ${SkillCampGuildIds}`);
const focusedOption = interaction.options.getFocused(true);
console.log(`focusedOption.name: ${focusedOption.name}`);
if (focusedOption.name == 'reason') {
choices = ['Purchase Table Reads', 'Redeem SkillStore Coupon'];
}
await interaction.respond(
choices.map(choice => ({ name: choice, value: choice })),
);
try {
const filtered = choices.filter(choice => choice.startsWith(focusedOption.value));
await interaction.respond(
filtered.map(choice => ({ name: choice, value: choice })),
);
} catch (error) {
console.error("error", error);
}
console.groupEnd();
},
async execute(interaction) {
const user = interaction.options.getUser('user');
const amount = interaction.options.getInteger('amount');
}
}
There should be though
When I run the bot, I have it say which files it's loaded in the console.
Would this be happening if it was a global command not a guild command?
How can I add it to the collection?
Yep. I literally copied and pasted from the guide