'How do I fix "TypeError: event.bind is not a function"?
I've tried to fix this error multiple times but failed each time, I can't think of any other way to fix this error anymore.
Error Output:
TypeError: event.bind is not a function
at load_dir (/home/runner/Radica/handler/setevents.js:15:38)
at /home/runner/Radica/handler/setevents.js:21:38
at Array.forEach (<anonymous>)
at module.exports (/home/runner/Radica/handler/setevents.js:21:25)
at /home/runner/Radica/index.js:56:34
at Array.forEach (<anonymous>)
at Object.<anonymous> (/home/runner/Radica/index.js:55:15)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
TypeError: event.bind is not a function
at load_dir (/home/runner/Radica/handler/setevents.js:15:38)
at /home/runner/Radica/handler/setevents.js:21:38
at Array.forEach (<anonymous>)
at module.exports (/home/runner/Radica/handler/setevents.js:21:25)
at /home/runner/Radica/index.js:56:34
at Array.forEach (<anonymous>)
at Object.<anonymous> (/home/runner/Radica/index.js:55:15)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
This is the code of the "setevents.js" file:
const fs = require("fs");
const allevents = [];
module.exports = (client) => {
try {
let dateNow = Date.now();
console.log(`${String("[x]".brightCyan)}` + ` • ` + `Now loading the Events...`.brightGreen)
const load_dir = (dir) => {
const event_files = fs.readdirSync(`./events/${dir}`).filter((file) => file.endsWith(".js"));
for (const file of event_files) {
try{
const event = require(`../events/${dir}/${file}`)
let eventName = file.split(".")[0];
if(eventName == "message") continue;
allevents.push(eventName);
client.on(eventName, event.bind(null, client));
}catch(e){
console.log(String(e.stack).grey.bgRed)
}
}
}
["client", "guild"].forEach(e => load_dir(e));
console.log(`[x]`.brightCyan + ` • ` + `Loaded all ${allevents.length} events after: `.brightGreen + `${Date.now() - dateNow}ms`.green)
try {
const stringlength2 = 69;
console.log("\n")
console.log(` ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓`.bold.yellow)
console.log(` ┃ `.bold.yellow + " ".repeat(-1 + stringlength2 - ` ┃ `.length) + "┃".bold.yellow)
console.log(` ┃ `.bold.yellow + `Logging into the BOT...`.bold.yellow + " ".repeat(-1 + stringlength2 - ` ┃ `.length - `Logging into the BOT...`.length) + "┃".bold.yellow)
console.log(` ┃ `.bold.yellow + " ".repeat(-1 + stringlength2 - ` ┃ `.length) + "┃".bold.yellow)
console.log(` ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛`.bold.yellow)
} catch {
/* */ }
} catch (e) {
console.log(String(e.stack).grey.bgRed)
}
};
IF YOU KNOW HOW TO FIX THIS ERROR PLEASE POST AN ANSWER
This is also my first post on here so my bad if I didn't missed something important or did something wrong etc...
Solution 1:[1]
I just had this issue and I got it fixed by adding this line of code to my message.js file
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Lin |
