Skip to main content

How do I solve the fn is not a function issue?

Before I added the reaction code, it worked fine just as a basic rule. But I wanted to make people have to accept the rules to continue to the discord. Then, I have issues, I think part of the issue is the intents and partials but I need the intents to allow the bot to start and the partials to allow the code to do reactions and channels so the rules bot can access the channel where the role adding/accepting rules will be.

Main.js

const Discord = require('discord.js');
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES",]},{partials: ["MESSAGE", "CHANNEL", "REACTION"]});
const prefix = '-';
const fs = require('fs');

client.commands = new Discord.Collection();

const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
    const command = require(`./commands/${file}`);
    client.commands.set(command.name, command);
}

client.once('ready', () =>{
    console.log('Roleplay Is Online');
});
client.on('guildMemberAdd', guildMember =>{
    let welcomeRole = guildMember.guild.roles.cache.find('973945417991589938');
 
    guildMember.roles.add(welcomeRole);
    guildMember.guild.channels.cache.get('974611802941968447').send(`Welcome <@${guildMember.user.id}> to our server! Make sure to check out the rules channel!`)
});

client.on('message', message => {
    if(!message.content.startsWith(prefix) || message.author.bot)return;

    const args = message.content.slice(prefix.length).split(/ +/);
    const command = args.shift().toLowerCase();

    if(command === 'rules'){
        client.commands.get('rules').execute(message, args, Discord);}else if(command === 'clear'){client.commands.get('clear').execute(message, args, Discord);}else if(command === 'kick'){client.commands.get('kick').execute(message, args, Discord);}else if(command === 'ban'){client.commands.get('ban').execute(message, args, Discord);
    }else if(command === 'mute'){client.commands.get('mute').execute(message, args, Discord);};
});

client.login('****************************************');

Rules.js

module.exports = {
    name: 'rules',
    description: 'rule command',
    async execute(message, args, Discord, client){
        const channel = '973944809444245504';
        const MemberRole = message.guild.roles.cache.find("973945417991589938");
 
        const MemberEmoji = ':ballot_box_with_check:';
 
        let embed = new Discord.MessageEmbed()
            .setColor('#e42643')
            .setTitle('Rules')
            .setDescription('Server Rules You Must Follow')
            .addFields(
                { name: 'Rule 1', value: 'Respect Everyone We Are All Human!', inline: false },
                { name: 'Rule 2', value: 'No Explicit Content Will Resault In Instant Ban', inline: false },
                { name: 'Rule 3', value: 'Do Not Spam @ Mods Or Owners You Will be Kicked If Repeat Offence = Ban', inline: false },
                { name: 'Rule 4', value: 'Each Channel Has Its Own Use So Use The Right One Please', inline: false },
                { name: 'Rule 5', value: 'No Trolling/Spamming This Resaults In Kick', inline: false },
                { name: 'Rule 6', value:'Any Exploiting of the Roleplay bot will resault in a character reset please report any bugs or exploits that are found Thanks.'},
                { name: 'Do You Agree', value: 'if you agree to the rules please click the tick below if you do not follow the rules you agree to will consit of punishments.'}
            )
 
        let messageEmbed = await message.channel.send(embed);
        messageEmbed.react(MemberEmoji);
 
        client.on('messageReactionAdd', async (reaction, user) => {
            if (reaction.message.partial) await reaction.message.fetch();
            if (reaction.partial) await reaction.fetch();
            if (user.bot) return;
            if (!reaction.message.guild) return;
 
            if (reaction.message.channel.id == channel) {
                if (reaction.emoji.name === MemberEmoji) {
                    await reaction.message.guild.members.cache.get(user.id).roles.add(MemberRole);
                }
            } else {
                return;
            }
 
        });
 
        client.on('messageReactionRemove', async (reaction, user) => {
 
            if (reaction.message.partial) await reaction.message.fetch();
            if (reaction.partial) await reaction.fetch();
            if (user.bot) return;
            if (!reaction.message.guild) return;
 
 
            if (reaction.message.channel.id == channel) {
                if (reaction.emoji.name === MemberEmoji) {
                    await reaction.message.guild.members.cache.get(user.id).roles.remove(MemberRole);
                }
            } else {
                return;
            }
        });
    }
 
}  

The error I'm getting when I run the command -rules is:

Roleplay Is Online
(node:17556) DeprecationWarning: The message event is deprecated. Use messageCreate instead
(Use `node --trace-deprecation ...` to show where the warning was created)
C:\Users\*****\Desktop\TBots\Roleplay\node_modules\@discordjs\collection\dist\index.js:122
      if (fn(val, key, this))
          ^

TypeError: fn is not a function
    at Map.find (C:\Users\*****\Desktop\TBots\Roleplay\node_modules\@discordjs\collection\dist\index.js:122:11)
    at Object.execute (C:\Users\*****\Desktop\TBots\Roleplay\commands\rules.js:6:54)
    at Client.<anonymous> (C:\Users\*****\Desktop\TBots\Roleplay\main.js:31:38)
    at Client.emit (node:events:527:28)
    at MessageCreateAction.handle (C:\Users\*****\Desktop\TBots\Roleplay\node_modules\discord.js\src\client\actions\MessageCreate.js:34:18)
    at Object.module.exports [as MESSAGE_CREATE] (C:\Users\*****\Desktop\TBots\Roleplay\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (C:\Users\*****\Desktop\TBots\Roleplay\node_modules\discord.js\src\client\websocket\WebSocketManager.js:351:31)
    at WebSocketShard.onPacket (C:\Users\*****\Desktop\TBots\Roleplay\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
    at WebSocketShard.onMessage (C:\Users\******\Desktop\TBots\Roleplay\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
    at WebSocket.onMessage (C:\Users\*******\Desktop\TBots\Roleplay\node_modules\ws\lib\event-target.js:199:18)
PS C:\Users\*******\Desktop\TBots\Roleplay> 
Via Active questions tagged javascript - Stack Overflow https://ift.tt/Aj5OMb1

Comments

Popular posts from this blog

How to show number of registered users in Laravel based on usertype?

i'm trying to display data from the database in the admin dashboard i used this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count(); echo $users; ?> and i have successfully get the correct data from the database but what if i want to display a specific data for example in this user table there is "usertype" that specify if the user is normal user or admin i want to user the same code above but to display a specific usertype i tried this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count()->WHERE usertype =admin; echo $users; ?> but it didn't work, what am i doing wrong? source https://stackoverflow.com/questions/68199726/how-to-show-number-of-registered-users-in-laravel-based-on-usertype

Why is my reports service not connecting?

I am trying to pull some data from a Postgres database using Node.js and node-postures but I can't figure out why my service isn't connecting. my routes/index.js file: const express = require('express'); const router = express.Router(); const ordersCountController = require('../controllers/ordersCountController'); const ordersController = require('../controllers/ordersController'); const weeklyReportsController = require('../controllers/weeklyReportsController'); router.get('/orders_count', ordersCountController); router.get('/orders', ordersController); router.get('/weekly_reports', weeklyReportsController); module.exports = router; My controllers/weeklyReportsController.js file: const weeklyReportsService = require('../services/weeklyReportsService'); const weeklyReportsController = async (req, res) => { try { const data = await weeklyReportsService; res.json({data}) console...

How to split a rinex file if I need 24 hours data

Trying to divide rinex file using the command gfzrnx but getting this error. While doing that getting this error msg 'gfzrnx' is not recognized as an internal or external command Trying to split rinex file using the command gfzrnx. also install'gfzrnx'. my doubt is I need to run this program in 'gfzrnx' or in 'cmdprompt'. I am expecting a rinex file with 24 hrs or 1 day data.I Have 48 hrs data in RINEX format. Please help me to solve this issue. source https://stackoverflow.com/questions/75385367/how-to-split-a-rinex-file-if-i-need-24-hours-data