TypeError: verification is not a function

Viewed 39

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("..");

1 Answers

I have successfully resolved the problem. I changed the way I exported functions from index.js. From the way it goes below to the way below it.

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})     
    }
}
   async function verification(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()
        var message = channel.send({embeds: [verifiactionEmbed]})
    }

    async function newInfo(id, string){
        const channel = client.channels.cache.get(id)
        const stringImport = string
        channel.send('sex')
    }

This is how both functions were created, asynchronous functions, so that discord.js could send messages and use its events.

I changed the way function is exported.

exports.Verification = verification;
exports.Info = newInfo;

welcome.js File where i need to access function exported from index.js

const index = require('../index.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
        index.Verification(channeldIDExport)
        await interaction.reply('Weryfikacja została ustawiona na kanale '+channelID.name + ' przez użytkownika '+interaction.user,{ephemeral: true})     
    }
}
Related