admin管理员组文章数量:1025202
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
andevent
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 calledbind
? Maybe you could check ifevent.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
1 Answer
Reset to default 2Make 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.
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
andevent
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 calledbind
? Maybe you could check ifevent.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
1 Answer
Reset to default 2Make 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.
本文标签: javascriptHow to fix quoteventbind is not a functionquotStack Overflow
版权声明:本文标题:javascript - How to fix "event.bind is not a function"? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745504152a2153527.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论