My code looks like this. I created the export verification function which sends a message from the embed to the channel provided by the user, command / welcome. There is a problem, each call to this function gives TypeError: verification is not a function. I have no idea why. It looks like an error with execute interaction here, because the code that checks for an error with the command indicates that there is simply some error.
index.js
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildBans, GatewayIntentBits.GuildEmojisAndStickers, GatewayIntentBits.GuildMembers] });
client.commands = new Collection();
const commandsPath = path.join(__dirname, 'commands');
const commandsFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandsFiles){
const filePath = path.join(commandsPath,file);
const command = require(filePath);
client.commands.set(command.data.name, command);
}
client.once('ready', () => {
console.log('Ready!');
});
module.exports = {
verification: function(id){
const channel = client.channels.cache.get(id)
const verifiactionEmbed = new EmbedBuilder()
.setColor(0x0099FF)
.setTitle('Zweryfikuj się na tym kanale')
.setDescription('Zareaguj na emotkę, żeby zweryfikować się!')
.setTimestamp()
channel.send({embeds: [verifiactionEmbed]})
}
}
client.on('interactionCreate', async interaction => {
if (!interaction.isChatInputCommand()) return;
const command = client.commands.get(interaction.commandName);
if (!command) return;
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
});
client.login(token);```
welcome.js
const { SlashCommandBuilder, Guild } = require("discord.js");
module.exports = {
data: new SlashCommandBuilder()
.setName('welcomechannel')
.setDescription('Ustaw kanał do weryfkacji nowych użytkowników')
.addChannelOption((channel) =>
channel
.setName('ch')
.setDescription('Wybierz kanał w którym chcesz ustawić weryfikacje nowych użytkowników')
.setRequired(true)
),
async execute(interaction){
channelID = interaction.options.getChannel('ch');
channeldIDExport = channelID.id
verification(channeldIDExport)
await interaction.reply('Weryfikacja została ustawiona na kanale '+channelID.name + ' przez użytkownika '+interaction.user,{ephemeral: true})
}
}
const {verification} = require("..");