I'm basically trying to code something where you need to send a message to a specific channel, and a specific message to send to get a specific role, basically like verifying as such but without the prefix but an error keeps popping up and i cant get rid of it.
The script i am trying to fix:
bot.on("message", async message => {
if(message.channel.id === '753928667427635230'){
if(message.content == 'test'){
let role = message.guild.roles.cache.find('757964609222344744')
let member = message.author.id
member.roles.add(role)
message.channel.send('script works')
}
}
The error code below:
(node:14284) UnhandledPromiseRejectionWarning: TypeError: fn is not a function
at Map.find (C:\Users\haxor\Desktop\HardWareProject\node_modules\@discordjs\collection\dist\index.js:161:17)
at Client.<anonymous> (C:\Users\haxor\Desktop\HardWareProject\main.js:37:50)
at Client.emit (events.js:315:20)
at MessageCreateAction.handle (C:\Users\haxor\Desktop\HardWareProject\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\haxor\Desktop\HardWareProject\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
my entire script:
const Discord = require('discord.js')
const bot = new Discord.Client()
const botsettings = require('./botsettings.json')
const fs = require('fs')
bot.commands = new Discord.Collection();
bot.aliases = new Discord.Collection();
fs.readdir("./commands/", (err, files) => {
if(err) console.log(err);
let jsfile = files.filter(f => f.split('.').pop() === 'js');
if(jsfile.length <= 0){
console.log('Commands aren\'t found!');
return;
}
jsfile.forEach((f) => {
let props = require(`./commands/${f}`);
console.log(`${f} loaded!`)
bot.commands.set(props.help.name, props);
props.help.aliases.forEach(alias => {
bot.aliases.set(alias, props.help.name);
})
})
})
bot.on("ready", async () => {
console.log(`Logged in as ${bot.user.username}`);
bot.user.setActivity(`HardLies`, {type: 'WATCHING' });
})
// Where the current error is at
bot.on("message", async message => {
if(message.channel.id === '753928667427635230'){
if(message.content == 'test'){
let role = message.guild.roles.cache.find('757964609222344744')
let member = message.author.id
member.roles.add(role)
message.channel.send('script works')
}
}
if(message.channel.type === 'dm') return;
if(message.author.bot) return;
let prefix = botsettings.prefix;
if(!message.content.startsWith(prefix)) return;
let args = message.content.slice(prefix.length).trim().split(/ +/g);
let cmd;
cmd = args.shift().toLowerCase();
let command;
let commandFile = bot.commands.get(cmd.slice(prefix.length));
if(commandFile) commandFile.run(bot, message, args);
if(bot.commands.has(cmd)){
command = bot.commands.get(cmd);
} else if(bot.aliases.has(cmd)){
command = bot.commands.get(bot.aliases.get(cmd));
}
try {
command.run(bot, message, args);
} catch (e){
return;
}
});
bot.login(botsettings.token);