javascript - How to fix "event.bind is not a function"? - Stack Overflow

I'm setting up a new Discord server, so that means I need to make a new custom bot for it. I was r

I'm setting up a new Discord server, so that means I need to make a new custom bot for it. I was redoing the index.js code and then I try starting it up for the first time and it is telling me "event.bind is not a function"? Where is the issue and how do I resolve it?

I have tried reinstalling Node.js, Enmap, and Discord.js but the problem keeps reoccurring.

fs.readdir("./events/", (err, files) => {
  if (err) return console.error(err);
  files.forEach(file => {
    const event = require(`./events/${file}`);
    const eventName = file.split(".")[0];
    client.on(eventName, event.bind(null, client));
  });
});

I'm setting up a new Discord server, so that means I need to make a new custom bot for it. I was redoing the index.js code and then I try starting it up for the first time and it is telling me "event.bind is not a function"? Where is the issue and how do I resolve it?

I have tried reinstalling Node.js, Enmap, and Discord.js but the problem keeps reoccurring.

fs.readdir("./events/", (err, files) => {
  if (err) return console.error(err);
  files.forEach(file => {
    const event = require(`./events/${file}`);
    const eventName = file.split(".")[0];
    client.on(eventName, event.bind(null, client));
  });
});
Share Improve this question asked Jan 19, 2019 at 22:10 PersikPersik 2755 gold badges11 silver badges20 bronze badges 3
  • Please identify for which value (and type) of file and event you get this error. – trincot Commented Jan 19, 2019 at 22:18
  • are you sure that every file in the events folder exports a function called bind? Maybe you could check if event.bind() is defined before trying to call it. – schu34 Commented Jan 19, 2019 at 22:18
  • The exports in events call client, message, and args – Persik Commented Jan 19, 2019 at 22:48
Add a ment  | 

1 Answer 1

Reset to default 2

Make sure your message.js is module.exports = (client, message) => {

The code is from https://anidiots.guide/first-bot/a-basic-mand-handler#main-file-changes so you might find more there.

Additionally, the loader is not checking if the file is a .js file, so make sure to only have .js files in the folder.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745504154a4630551.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信