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

Confusion between commands.Bot and discord.Client | Which one should I use?

Whenever you look at YouTube tutorials or code from this website there is a real variation. Some developers use client = discord.Client(intents=intents) while the others use bot = commands.Bot(command_prefix="something", intents=intents) . Now I know slightly about the difference but I get errors from different places from my code when I use either of them and its confusing. Especially since there has a few changes over the years in discord.py it is hard to find the real difference. I tried sticking to discord.Client then I found that there are more features in commands.Bot . Then I found errors when using commands.Bot . An example of this is: When I try to use commands.Bot client = commands.Bot(command_prefix=">",intents=intents) async def load(): for filename in os.listdir("./Cogs"): if filename.endswith(".py"): client.load_extension(f"Cogs.{filename[:-3]}") The above doesnt giveany response from my Cogs ...

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

Where and how is this Laravel kernel constructor called? [closed]

Where and how is this Laravel kernel constructor called? public fucntion __construct(Application $app, $Router $roouter) { } I have read the documentation and some online tutorial but I can find any clear explanation. I am learning Laravel and I am wondering where does this kernel constructor receives its arguments from. "POSTMOTERM" CLARIFICATION: Here is more clarity.I have checked the boostrap/app.php and it is only used for boostrapping the interfaces into the container class. What is not clear to me is where and how the Kernel class is instatiated and the arguments passed to the object calling the constructor.Something similar to; obj = new kernel(arg1,arg2) or, is the framework using some magic functions somewhere? Special gratitude to those who burn their eyeballs and brain cells on this trivia before it goes into a full blown menopause alias "MARKED AS DUPLICATE". To some of the itchy-finger keyboard warriors, a.k.a The mods,because I believe in th...